Operators And Expressions In Php(Php ) Questions and Answers
Question 1. What will be the output of the following PHP code ?
Error
Hello World
Nothing
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 ?
redredred
redred
red
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 ?
# Hello world
Hello world# Hello world
Hello world
Error
Explanation:-
Answer: Option A. -> # Hello world # is a single line comment.
Question 4. What will be the output of the following PHP code ?
Error
Hello World
Nothing
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 ?
Hello world
Hello world in italics
Nothing
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 ?
104
410
1400
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 ?
$winner/$looser
/$looser
/
$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 ?
$winner$looser
$looser
\
$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 ?
$winner$looser
$looser
\
$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 ?
5
10
15
Error
Explanation:-
Answer: Option C. -> 15 You can access the global variable using $GLOBALS[‘globalvariablename’].