PHP Math
PHP provides a variety of built-in functions for mathematical operations. Here are some commonly used functions for math in PHP:
- Basic arithmetic:
+
: Addition-
: Subtraction*
: Multiplication/
: Division%
: Modulo (remainder after division)
- Mathematical functions:
abs()
: Absolute valuesqrt()
: Square rootpow()
: Exponentiationexp()
: Exponential functionlog()
: Natural logarithmlog10()
: Base-10 logarithmround()
: Rounds a number to the nearest integerfloor()
: Rounds a number down to the nearest integerceil()
: Rounds a number up to the nearest integerrand()
: Generates a random number
- Trigonometric functions:
sin()
: Sinecos()
: Cosinetan()
: Tangentasin()
: Arcsineacos()
: Arccosineatan()
: Arctangent
- Constants:
M_PI
: The value of π (pi)M_E
: The value of Euler’s number (e)
These are just a few examples of the math functions available in PHP. You can find more functions and detailed information in the PHP documentation.