Operators And Expressions In Php(Php ) Questions and Answers

Question 1. What will be the output of the following PHP code ?
  1.    Error
  2.    Hello World
  3.    Nothing
  4.    Missing semicolon error
Explanation:-
Answer: Option C. -> Nothing
If you need to output something onto the screen you’ll need to use echo or print_r.

Question 2. What will be the output of the following PHP code ?
  1.    redredred
  2.    redred
  3.    red
  4.    Error
Explanation:-
Answer: Option C. -> red
In PHP, all variables are case-sensitive.

Question 3. What will be the output of the following PHP code ?
  1.    # Hello world
  2.    Hello world# Hello world
  3.    Hello world
  4.    Error
Explanation:-
Answer: Option A. -> # Hello world
# is a single line comment.

Question 4. What will be the output of the following PHP code ?
  1.    Error
  2.    Hello World
  3.    Nothing
  4.    Missing semicolon error
Explanation:-
Answer: Option A. -> Error
The statement should be print_r(‘Hello World’) to print Hello world. Also if there is only one line then there is no requirement of a semicolon, but it is better to use it.

Question 5. What will be the output of the following PHP code ?
  1.    Hello world
  2.    Hello world in italics
  3.    Nothing
  4.    Error
Explanation:-
Answer: Option B. -> Hello world in italics
You can use tags like italics, bold etc. inside php script.

Question 6. What will be the output of the following PHP code ?
  1.    104
  2.    410
  3.    1400
  4.    4100
Explanation:-
Answer: Option C. -> 1400
The value returned from the function is 0, and value of a is 10, value of b is 4 and c is 0.

Question 7. What will be the output of the following PHP code ?
  1.    $winner/$looser
  2.    /$looser
  3.    /
  4.    $looser
Explanation:-
Answer: Option C. -> /
Since variables $winner and $looser is not defined we only see / as output.

Question 8. What will be the output of the following PHP code ?
  1.    $winner$looser
  2.    $looser
  3.    \
  4.    $looser
Explanation:-
Answer: Option D. -> $looser
As there is a backslash before $ it takes it as a string and not a variable therefore we get $looser as the output.

Question 9. What will be the output of the following PHP code ?
  1.    $winner$looser
  2.    $looser
  3.    \
  4.    $looser
Explanation:-
Answer: Option C. -> \
Since two backslashes are used together, a single backslash is printed on the screen and as $looser is not initialised only single backslash is printed.

Question 10. What will be the output of the following PHP code ?
  1.    5
  2.    10
  3.    15
  4.    Error
Explanation:-
Answer: Option C. -> 15
You can access the global variable using $GLOBALS[‘globalvariablename’].