Guided Notes

Conditionals: if, switch & match

Making decisions with if/elseif/else, switch, and PHP 8's match expression, and writing clear conditions.

if, elseif, else

Slide 1 / 5

Run code only when a condition is true: if ($score >= 90) { $grade = "A"; } elseif ($score >= 80) { $grade = "B"; } else { $grade = "C"; }

Conditions are checked top to bottom; the first true one wins, so order matters — put the most specific checks first. Always use braces, even for one line; it prevents bugs when someone adds a second line later.

← Operators