PHP Math
PHP provides a comprehensive set of math functions, built into the core of the language, which allow you to perform basic arithmetic, trigonometry, random number generation, rounding, and more. Here's an overview of common PHP math functions:
Basic Arithmetic
PHP uses standard operators for arithmetic:
Common Math Functions
Function | Description |
---|---|
abs($x) |
Absolute value of $x |
ceil($x) |
Rounds $x up to the nearest integer |
floor($x) |
Rounds $x down to the nearest integer |
round($x) |
Rounds $x to the nearest integer |
max($a, $b, ...) |
Returns the highest value |
min($a, $b, ...) |
Returns the lowest value |
pow($x, $y) |
Raises $x to the power of $y |
sqrt($x) |
Square root of $x |