Originally published on zero2php.dev — part of the Zero to PHP course. View this lesson on the original site.

Arithmetic

Integers and floats participate in normal arithmetic:

<?php

declare(strict_types=1);

$a = 10;
$b = 3;
echo $a + $b, "\n";
echo $a / $b, "\n"; // float division
echo intdiv($a, $b), "\n";

Caveats

Gotcha: floating point is not exact money math—later courses address decimal libraries when needed.

Modulo: $a % $b gives remainder; useful for wrap-around logic.

Exercise

Set $a = 25 and $b = 7, then echo intdiv($a, $b) so the output is 3.

From Zero to PHP — PHP foundations: environment, syntax, and values