From http://www.w3schools.com (Copyright Refsnes Data)
The Switch statement in PHP is used to perform one of several different actions based on one of several different conditions.
If you want to select one of many blocks of code to be executed, use the Switch statement.
The switch statement is used to avoid long blocks of if..elseif..else code.
switch (expression) { case label1: code to be executed if expression = label1; break; case label2: code to be executed if expression = label2; break; default: code to be executed if expression is different from both label1 and label2; } |
This is how it works:
<html> <body> <?php switch ($x) { case 1: echo "Number 1"; break; case 2: echo "Number 2"; break; case 3: echo "Number 3"; break; default: echo "No number between 1 and 3"; } ?> </body> </html> |
From http://www.w3schools.com (Copyright Refsnes Data)