The PHP if
and else
statements let a script decide whether to run a chunk of code based on a condition. The if
statement runs a chunk of code if the condition is true or skips it if the condition is false. if
combined with else
runs one chunk if the condition is true, or the other chunk if the condition is false.
PHP lets you take things further, and chain several decision-making blocks together, with each block having its own condition to test. To do this, you use the elseif
statement.