xxxxxxxxxx
switch ($i) {
case 0:
echo "i equals 0";
break;
case 1:
echo "i equals 1";
break;
case 2:
echo "i equals 2";
break;
default:
echo "i is not equal to 0, 1 or 2";
}
xxxxxxxxxx
$age=20;
switch ($age) {
case 19:
echo "Age is 18";
break;
case 20:
echo "Age is 20";
break;
case 21:
echo "Age is 21";
break;
}
xxxxxxxxxx
switch (fruit) {
case apple:
code to be executed if fruit=apple;
break;
case banana:
code to be executed if fruit=banana;
break;
default:
code to be executed if fruit is different from all fruits;
}
xxxxxxxxxx
$fruit = "apple";
switch ($fruit) {
case "apple":
echo "doctor";
break;
case "banana":
echo "monkey";
break;
default:
echo "things";
}//doctor
xxxxxxxxxx
switch ($element) {
case 0:
echo "i es igual a 0";
break;
case 1:
echo "i es igual a 1";
break;
case 2:
echo "i es igual a 2";
break;
}
xxxxxxxxxx
switch ($i) {
case 0:
echo "i ist gleich 0";
break;
case 1:
echo "i ist gleich 1";
break;
case 2:
echo "i ist gleich 2";
break;
}
xxxxxxxxxx
<?php
switch ($i) {
case 0:
echo "i equals 0";
break;
case 1:
echo "i equals 1";
break;
case 2:
echo "i equals 2";
break;
default:
echo "i is not equal to 0, 1 or 2";
}
?>
xxxxxxxxxx
$fruit = "apple";
switch ($fruit) {
case "apple":
echo "Selected fruit is apple.";
break;
case "banana":
echo "Selected fruit is banana.";
break;
case "orange":
echo "Selected fruit is orange.";
break;
default:
echo "Selected fruit is not apple, banana, or orange."
}
xxxxxxxxxx
<?php
// switch statement:
switch ($i) {
case 0:
echo "i equals 0";
break;
case 1:
echo "i equals 1";
break;
case 2:
echo "i equals 2";
break;
default:
echo "default message";
}
?>
xxxxxxxxxx
switch ($variable) {
case 'value1':
// Code to be executed when $variable is equal to 'value1'
break;
case 'value2':
// Code to be executed when $variable is equal to 'value2'
break;
default:
// Code to be executed when $variable doesn't match any case
}