switch (expression) {
case value1:
statement1;
break;
case value2:
statement2;
break;
...
default:
statement;
}
$color = "red";
switch ($color) {
case "red":
echo "Color is red!";
break;
case "green":
echo "Color is green!";
break;
case "blue":
echo "Color is blue!";
break;
default:
echo "Color is not red, green or blue!";
}
$x = 2;
switch ($x) {
case 1:
echo "Number is one!";
break;
case 2:
echo "Number is two!";
break;
case 3:
echo "Number is three!";
break;
default:
echo "Number is not one, two or three!";
}
$fruits = array("apple", "banana", "cherry");
$fruit = "banana";
switch ($fruit) {
case $fruits[0]:
echo "Fruit is apple!";
break;
case $fruits[1]:
echo "Fruit is banana!";
break;
case $fruits[2]:
echo "Fruit is cherry!";
break;
default:
echo "Fruit is not apple, banana or cherry!";
}