anantamu.com


PHP Switch


The switch statement is similar to a series of IF statements on the same expression, variable compares with value with multiple cases. Once the case match is found, a block of code is executed. one label have different name then to go for switch case, that is best choice.


SWITCH Statement

<?php 
 $a=0;
switch ($a) {
    case 0:
        echo "a equals to 0";
        break;
    case 1:
        echo "a equals to 1";
        break;
}  
?>

Result: a equals to 0