PHP Switch
PHP Switch
Switch syntax
switch (x) {
case x1:
if x=x1 then execute statement
break;
case x2:
if x=x2 then execute statement
break;
case x3:
if x=x3 then execute statement
break;
…
default:
statement to be executed if x is not equal to x1, x2 or x3;
}
Switch example
<html> <body> <?php $x = 1; switch ($x) { case 1: echo "First case"; break; case 2: echo "Second case"; break; case 3: echo "Third case"; break; default: echo "Default case"; } ?> </body> </html>
Result
First case