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;
}
$fruit = "apple";
switch ($fruit) {
case "apple":
echo "doctor";
break;
case "banana":
echo "monkey";
break;
default:
echo "things";
}//doctor
<?php
switch ($i) {
case "apple":
echo "i is apple";
break;
case "bar":
echo "i is bar";
break;
case "cake":
echo "i is cake";
break;
}
?>
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;
}
int value = 0;
switch (value) {
case 0:
// do something
break;
case 1:
// do something else
break;
default :
// something if anything not match
}
<?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";
}
?>
<?php
// Ce switch:
switch ($i) {
case 0:
echo "i égal 0";
break;
case 1:
echo "i égal 1";
break;
case 2:
echo "i égal 2";
break;
}
// Équivaut à:
if ($i == 0) {
echo "i égal 0";
} elseif ($i == 1) {
echo "i égal 1";
} elseif ($i == 2) {
echo "i égal 2";
}
?>
<?php
$i=250;
Switch($i)
{
Case 150:
echo "Value is 150";
Break;
Case 250:
echo "Value is 250";
Break;
Case 350:
echo "Value is 350";
Break;
Case 450:
echo "Value is 450";
Break;
Default:
echo "Enter Correct Value";
Break;
}
?>
switch ($your_variable)
{
case 1:
case 2:
echo "the value is either 1 or 2.";
break;
}