Operators And Expressions In Php - Study Mode
[#106] What will be the output of the following PHP code ? <?php $x
echo "$x"
?>
Correct Answer
(C) Nothing
Explanation
Solution: Since the variable x is not initialised it is not storing any value, therefore nothing will be printed on the screen.
[#107] What will be the output of the following PHP code ? <?php $x = 5
{ $x = 10
echo "$x"
} echo "$x"
?>
Correct Answer
(A) 1010
Explanation
Solution: Varibale x stores the value 10 and not 5.
[#108] What will be the output of the following PHP code ? <?php $x = 5
{ echo "$x"
} ?>
Correct Answer
(B) 5
[#109] What will be the output of the following PHP code ? <?php $x = 5
function fun () { echo "$x"
} fun ()
?>
Correct Answer
(C) Nothing
Explanation
Solution: The variable x is not defined inside the function fun(), therefore nothing is printed on the screen.
[#110] What will be the output of the following PHP code ? <?php $x = 5
function fun () { $x = 10
echo "$x"
} fun ()
echo "$x"
?>
Correct Answer
(B) 105
(F) 105
Explanation
Solution: First when the function is called variable x is initialised to 10 so 10 is printed later the global value 5 is printed.