PHP provides powerful built-in mathematical functions that allow you to perform basic to advanced math operations easily.
PHP supports all standard arithmetic operations:
+
Addition-
Subtraction*
Multiplication/
Division%
Modulus (Remainder)<?php $a = 15; $b = 4; echo $a + $b; // 19 echo $a - $b; // 11 echo $a * $b; // 60 echo $a / $b; // 3.75 echo $a % $b; // 3 ?>
abs(x)
– Returns the absolute (positive) valueround(x)
– Rounds a numberceil(x)
– Rounds upfloor(x)
– Rounds downsqrt(x)
– Returns the square rootpow(x, y)
– Raises x to the power ymax(x, y...)
– Returns the highest valuemin(x, y...)
– Returns the lowest valuerand(min, max)
– Returns a random number<?php echo abs(-20); // 20 echo round(3.4); // 3 echo ceil(3.4); // 4 echo floor(3.9); // 3 echo sqrt(16); // 4 echo pow(2, 3); // 8 echo max(4, 7, 1); // 7 echo min(4, 7, 1); // 1 echo rand(10, 99); // Random number between 10–99 ?>
rand()
to build games or lucky draw apps!
round()
, abs()
, sqrt()
, rand()
, etc.Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!