Complete the code to start a switch statement with the variable $color.
<?php $color = 'red'; switch([1]) { case 'red': echo 'Stop'; break; default: echo 'Go'; } ?>
The switch statement must use the variable $color to check its value.
Complete the code to print 'Go' when the color is not 'red' or 'yellow'.
<?php $color = 'green'; switch ($color) { case 'red': echo 'Stop'; break; case 'yellow': echo 'Caution'; break; [1]: echo 'Go'; } ?>
The default case runs when no other case matches.
Fix the error in the switch statement to correctly break after the 'yellow' case.
<?php $color = 'yellow'; switch ($color) { case 'red': echo 'Stop'; break; case 'yellow': echo 'Caution'; [1] default: echo 'Go'; } ?>
The break statement stops the switch from continuing to the next cases.
Fill both blanks to create a switch that prints 'Weekend' for 'Saturday' and 'Sunday', and 'Weekday' otherwise.
<?php $day = 'Sunday'; switch([1]) { case 'Saturday': case [2]: echo 'Weekend'; break; default: echo 'Weekday'; } ?>
The switch uses $day to check the day. The second case must be the string 'Sunday' to group weekend days.
Fill all three blanks to create a switch that prints 'Low', 'Medium', or 'High' based on the $level variable.
<?php $level = 2; switch([1]) { case 1: echo [2]; break; case 2: echo [3]; break; default: echo 'High'; } ?>
The switch checks the variable $level. For case 1, it prints 'Low'. For case 2, it prints 'Medium'. Otherwise, it prints 'High'.