PHP
June 3, 2026 3 min read

PHP Mathematical Functions: Performing Mathematical Operations with Ease

HS
HEMANT SINGH
Technical Writer & Educator
  1. abs(n)
  2. Return absolute value
  3. base_convert(n, from, to)
  4. Convert a number from one base to another
  5. ceil(n)
  6. Round up number nearest integer
  7. floor(n)
  8. Round down a number nearest integer
  9. sin(n)
  10. Return sine of a number
  11. cos(n)
  12. Return cosine of a number
  13. tan(n)
  14. Return tangent of a number
  15. hypot(b, h)
  16. Calculate the hypotenuse  of right angle triangle
  17. log(n)
  18. Return natural logarithm of a number
  19. log10(n)
  20. Return the base 10 logarithm of a number
  21. max(arg1, arg2)
  22. Return max value number from an array
  23. min(arg1, arg2)
  24. Return min value number from an array
  25. mt_rand(from, to)
  26. Generate a random number it is fast than rand
  27. pi()
  28. Return pi value
  29. pow(base, exponent)
  30.  Return power of a number
  31. rand(from, to)
  32. Return random value
  33. round(n)
  34. Round a floating-point number
  35. sqrt(n)
  36. Return square root of a given number

example

<?php 

echo "abs <br>";
echo abs(-90);
echo "<br>";


echo "base_convert <br>";
echo base_convert(5, 10, 2);
echo "<br>";


echo "ceil <br>";
echo ceil(1.2);
echo "<br>";


echo "floor <br>";
echo floor(1.9);
echo "<br>";


echo "sin <br>";
echo sin(90);
echo "<br>";


echo "cos <br>";
echo cos(90);
echo "<br>";


echo "tan <br>";
echo tan(90);
echo "<br>";


echo "hypot <br>";
echo hypot(2, 3);
echo "<br>";


echo "log <br>";
echo log(10);
echo "<br>";


echo "log10 <br>";
echo log10(10);
echo "<br>";


echo "max <br>";
echo max([1,2,3,4,5]);
echo "<br>";


echo "min <br>";
echo min([1,2,3,4,5]);
echo "<br>";


echo "mt_rand <br>";
echo mt_rand(1,1000);
echo "<br>";


echo "pi <br>";
echo pi();
echo "<br>";


echo "pow <br>";
echo pow(2, 3);
echo "<br>";


echo "rand <br>";
echo rand(1, 1000);
echo "<br>";


echo "round <br>";
echo round(3.12);
echo "<br>";


echo "sqrt <br>";
echo sqrt(9);
echo "<br>";

?>