PHP Math Function
PHP provides a number of built-in functions for performing mathematical operations. Some of the most commonly used math functions in PHP are:
abs
: This function returns the absolute value of a number.max
: This function returns the highest value among a set of values.min
: This function returns the lowest value among a set of values.round
: This function rounds a floating-point number to the nearest integer or to a specified number of decimal places.sqrt
: This function returns the square root of a number.pow
: This function returns the result of a number raised to a power.
Here's an example of how you might use some of these functions in a PHP script:
$a = 10; $b = -5; $c = 3.14; echo abs($b) . "\n"; // Outputs 5 echo max($a, $b, $c) . "\n"; // Outputs 10 echo min($a, $b, $c) . "\n"; // Outputs -5 echo round($c) . "\n"; // Outputs 3 echo sqrt($a) . "\n"; // Outputs 3.16227766 echo pow($a, $b) . "\n"; // Outputs 0.00001
You can find a complete list of the math functions available in PHP in the documentation: