Numbers and Math
Arithmetic: + - * / % and ** for powers. intdiv gives integer division. Math helpers: abs, ceil, floor, round, sqrt, max, min, pow, rand and random_int. is_numeric checks whether a value looks like a number.
Example
echo 7 / 2, " ", intdiv(7, 2), " ", 7 % 2, " ", 2 ** 10, "\n";
echo round(3.14159, 2), " ", ceil(4.1), " ", floor(4.9), "\n";
echo sqrt(81), " ", max(3, 9, 5), " ", abs(-7), "\n";
$n = random_int(1, 6);
var_dump($n >= 1 && $n <= 6);
var_dump(is_numeric("12.5"));Result
3.5 3 1 1024 3.14 5 4 9 9 7 bool(true) bool(true)
Exercise
Round to 2 decimals.
(3.14159, 2)Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.