×

php · level 1 · unit 4 · lesson 1

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

An if runs code only when its is true.

Picture a fork in the path with a sign: Is it Saturday? An if asks a condition like that. If the answer is yes, PHP runs the lines inside. If not, it skips past them.

PHP answers every condition with true or false. A value that can only be one of these two is a . To ask whether two values match exactly, use three equals signs, ===. One = puts a value in a box.

The condition goes in round brackets. The lines that belong to the if sit inside curly brackets, as one . Indent them with four spaces so people can see the block too.

<?php
$day = "Saturday";
if ($day === "Saturday") {
    echo "Pancakes for breakfast!\n";
}
echo "Time to get dressed.\n";

Lines after the closing } sit outside the if, so they run every time.