php case condition code example
Example 1: php switch
$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;
}
Example 2: switch case php
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;
}
Example 3: switch case php
$fruit = "apple";
switch ($fruit) {
case "apple":
echo "doctor";
break;
case "banana":
echo "monkey";
break;
default:
echo "things";
}
Example 4: case statement in php
<?php
switch ($i) {
case "apple":
echo "i is apple";
break;
case "bar":
echo "i is bar";
break;
case "cake":
echo "i is cake";
break;
}
?>
Example 5: php switich
switch (n) {
case label1:
code to be executed if n=label1;
break;
case label2:
code to be executed if n=label2;
break;
case label3:
code to be executed if n=label3;
break;
...
default:
code to be executed if n is different from all labels;
}
Example 6: is switch case case sensitive in php
<?php
$smart = "cRikEy";
switch (strtolower($smart)) {
case "crikey":
echo "Crikey";
break;
case "hund":
echo "Hund";
break;
case "kat":
echo "Kat";
break;
default:
echo "Alt Andet";
}
?>