We can use the switch statement to select one of many blocks of code to be executed.
General Format
switch (val)
{
case label1:
code to be executed if n=label1;
break;
case label2:
code to be executed if n=label2;
break;
default:
code to be executed if n is different from both label1 and label2;
}
Example
<?php
$val=1;
switch($val){
case 1 : echo “Sunday”;break;
case 2 : echo “Monday”;break;
case 3 : echo “Tuesady”;break;
case 4 : echo “Wednesady”;break;
case 5 : echo “Thursday”;break;
case 6 : echo “Friday”;break;
case 7 : echo “Saturday”;break;
default : echo “Sunday”;break;
}
?>
Output
Sunday