Basic Php(Php ) Questions and Answers

Question 1. With the introduction of namespaces, the same function name can be used in multiple places.
  1.    TRUE
  2.    FALSE
Explanation:-
Answer: Option A. -> TRUE

Question 2. As the namespace size grows, using namespaces can become a little repetitious, but PHP also provides the . . . . . statement, which allows you to alias a specific namespace.
  1.    php
  2.    grant
  3.    use
  4.    label
Explanation:-
Answer: Option C. -> use

Question 3. Multiple namespaces cannot be defined in the same file.
  1.    TRUE
  2.    FALSE
Explanation:-
Answer: Option B. -> FALSE

Question 4. Within a namespace, for accessing the built-in PHP classes you can prefix the class name with a . . . . . and let PHP look in the global class list.
  1.    percent
  2.    ampersand
  3.    asterix
  4.    backslash
Explanation:-
Answer: Option D. -> backslash

Question 5. Which of the below namespace declaration is correct?
  1.    namespace ORA:
  2.    namespace 1_RA;
  3.    namespace ORA;
  4.    namespace ORA_#;
Explanation:-
Answer: Option C. -> namespace ORA;

Question 6. What will be the output of the following PHP code?
  1.    1
  2.    Error
  3.    1234
  4.    2
Explanation:-
Answer: Option C. -> 1234
The (array) is a cast operator which is used for converting values from other data types to array.

Question 7. Which of the following PHP statements will output Hello World on the screen?
1. echo (“Hello World”);
2. print (“Hello World”);
3. printf (“Hello World”);
4. sprintf (“Hello World”);
  1.    1 and 2
  2.    1, 2 and 3
  3.    All of the mentioned
  4.    1, 2 and 4
Explanation:-
Answer: Option B. -> 1, 2 and 3
echo(), print() and printf() all three can be used to output a statement onto the screen. The sprintf() statement is functionally identical to printf() except that the output is assigned to a string rather than rendered to the browser.

Question 8. What will be the output of the following code?
  1.    Error
  2.    My name is BobBob
  3.    My name is BobMy name is Bob
  4.    My name is Bob Bob
Explanation:-
Answer: Option C. -> My name is BobMy name is Bob
The $bar = &$foo; line will reference $foo via $bar.

Question 9. What will be the output of the following PHP code?
  1.    Error
  2.    35 students
  3.    35
  4.    25 students
Explanation:-
Answer: Option C. -> 35
The integer value at the beginning of the original $total string is used in the calculation. However if it begins with anything but a numerical value, the value will be 0.

Question 10. What will be the output of the following PHP code?
  1.    a
  2.    Error
  3.    $var
  4.    r
Explanation:-
Answer: Option D. -> r
PHP treats strings in the same fashion as arrays, allowing for specific characters to be accessed via array offset notation.