PHP Switch Statement
block of coding;
if the condition equals value1;
break;
case “value2” :
block of coding;
if the condition equals value2;
break;
default :
block of coding;
if the condition does not equal value1 or value2;
break;
}
?>
There can be many cases listed. For example purposes, we only show two. There are a few things happening at the same time here :
1. The switch condition is examined and a value is found.
2. The condition value is passed through the cases.
3. If the value matches a case value, the code in that block is executed.
4. If the value does not match any of the case values, the default section is executed.
5. Once a block of coding is finished, the BREAK command is used to jump out of the switch/case area.
case “40″ :
echo “The value equals 40.”;
break;
case “32″ :
echo “The value equals 32.”;
break;
default :
echo “The value is not 40 or 32.”;
break;
}
?>
And the result :