WeCodeAcademy

PHP Numbers and Math

ExamplePHP
<?php
echo 17 + 5, "\n";
echo 17 / 5, "\n";
echo intdiv(17, 5), "\n";
echo 17 % 5, "\n";
echo 2 ** 10, "\n";
echo round(3.14159, 2), "\n";
echo floor(2.7), " ", ceil(2.1), "\n";
echo max(3, 9, 4), " ", min(3, 9, 4), "\n";
echo abs(-5), " ", sqrt(81), "\n";
var_dump(is_numeric("12.5"));
var_dump(PHP_INT_MAX);
Output
22
3.4
3
2
1024
3.14
2 3
9 3
5 9
bool(true)
int(9223372036854775807)

Unlike C or Java, / always gives a decimal when the division is not exact. Use intdiv for whole-number division.

Quick check

Which function does whole-number division?

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.