Home »
MCQs »
PHP MCQs
What will be the output of the following PHP code (21)?
90. What will be the output of the following PHP code?
<?php
$car = "Honda";
switch ($car) {
case "Honda":
echo "You selected Honda.";
case "BMW":
echo "You selected BMW.";
case "AUDI":
echo "You selected Audi.";
default:
echo "None is selected.";
}
?>
- You selected Honda.
- You selected Honda.You selected BMW.
- You selected Honda.You selected BMW.You selected Audi.
- You selected Honda.You selected BMW.You selected Audi.None is selected.
Answer: D) You selected Honda.You selected BMW.You selected Audi.None is selected.
Explanation:
In the above PHP Script, break statements were not used in the case blocks. The value of $car is "Honda", so the first case executes and then all other blocks will be executed because the switch statement executes the blocks from the matched case block to the bottom if the break statement is not there.