Control Structures
If, Elseif, Else Statements
<?php
$x = 10;
$y = 20;
if ($x > $y) {
echo "x is greater than y";
} elseif ($x == $y) {
echo "x is equal to y";
} else {
echo "x is less than y";
}
?>Switch Statement
<?php
$favcolor = "blue";
switch ($favcolor) {
case "red":
echo "Your favorite color is red!";
break;
case "blue":
echo "Your favorite color is blue!";
break;
case "green":
echo "Your favorite color is green!";
break;
default:
echo "Your favorite color is neither red, blue, nor green!";
}
?>While Loop
For Loop
Foreach Loop
Last updated