Conditions let your program make decisions. You test an expression, and depending on whether it is true or false, a different block of code runs.

Comparison operators

  • == equal to  /  === equal and of the same type.
  • != not equal to.
  • > greater than  /  < less than.
  • >= and <= greater/less than or equal to.

The if / else structure

  1. if tests a condition.
  2. elseif tests another condition if the first one is false.
  3. else runs when no condition is true.

For example: if $age >= 18 you display “Adult”, otherwise “Minor”. You can also combine conditions with && (and) and || (or).

Key point: be careful not to mix up = (assignment) and == (comparison). It is the classic beginner’s mistake.