×

php · level 1 · unit 3 · lesson 2

  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

PHP is a calculator that never gets tired.

+ adds, - takes away, * multiplies and / divides. Each of these symbols is an . PHP does * and / before + and -, like school maths, and brackets go first of all.

Dividing can give a number with a decimal point, like 3.5. That kind of number is a . gettype calls it a double, an older name for the same thing.

For whole numbers, intdiv(7, 2) divides and drops the leftover, giving 3. The % operator gives the , the part left over, so 7 % 2 is 1.

<?php
$slices = 7;
$friends = 2;
echo $slices / $friends . "\n";
echo intdiv($slices, $friends) . "\n";
echo $slices % $friends . "\n";

Brackets change the order, so 2 + 3 * 4 is 14 but (2 + 3) * 4 is 20.