Switch Statement
Posted by webinfiniteMar 4
A PHP switch statement is almost like an IF statement except it is good to use a switch statement when you want to compare many results on the same variable.
Example with integer.
<?php
switch ($i):
case 0:
echo "i = 0";
break;
case 1:
echo "i = 1";
break;
case 2:
echo "i = 2";
break;
default:
echo "i is not equal to 0, 1 or 2";
endswitch;
?> Example with a string.
<?php
switch ($i) {
case "eagle:
echo "i is eagle";
break;
case "hawk":
echo "i is hawk";
break;
case "blue jay":
echo "i is blue jay";
break;
}
?>
No comments