The switch statement to select one of many blocks of code to be executed.the following syntax and example of switch statement in php.
<?php
switch(expression or variable)
{
case label1:
code to be executed if variable or expression=label1;
break;
case label1:
code to be executed if variable or expression=label2;
break;
default;
code to be executed if variable or expression= is different from both label1 and label2;
break;
}
?>
<?php
$i = 'apple';
switch ($i)
{
case "apple":
echo "is apple";
break;
case "bar":
echo "is banana";
break;
case "cake":
echo "is whatermaln";
break;
}
?>
is apple