switch structure ----------------------------------------- <?php if ($i == 0) { echo "i equals 0"; } elseif ($i == 1) { echo "i equals 1"; } elseif ($i == 2) { echo "i equals 2"; }
switch ($i) { case 0: echo "i equals 0"; break; case 1: echo "i equals 1"; break; case 2: echo "i equals 2"; break; } ?> ------------------------------------------------ <?php
switch ($totaltime) {
case ($totaltime < 1): echo "That was fast!"; break;
case ($totaltime > 1): echo "Not fast!"; break;
case ($totaltime > 10): echo "That's slooooow"; break; }
?> ------------------------------------------------ <?php switch ($i) { case "apple": echo "i is apple"; break; case "bar": echo "i is bar"; break; case "cake": echo "i is cake"; break; } ?> ------------------------------------------------ <?php switch($beer) { case 'tuborg'; case 'carlsberg'; case 'heineken'; echo 'Good choice'; break; default; echo 'Please make a new selection...'; break; } ?> ---------------------------------------------- <?php function getChineseZodiac($year){
switch ($year % 12) : case 0: return 'Monkey'; // Years 0, 12, 1200, 2004... case 1: return 'Rooster'; case 2: return 'Dog'; case 3: return 'Boar'; case 4: return 'Rat'; case 5: return 'Ox'; case 6: return 'Tiger'; case 7: return 'Rabit'; case 8: return 'Dragon'; case 9: return 'Snake'; case 10: return 'Horse'; case 11: return 'Lamb'; endswitch; }
echo getChineseZodiac(2016); ?> -------------------------------------------
|