PHP pow() Function
The PHP pow() function returns the base raise to the power of exponent. If both arguments of the function are non-negative integers the return type will be integer, else the return type will be float. In special cases it returns the following:
- If the exponent is zero, then the result is 1.0.
- If the exponent is NAN, then the result is NAN.
- If the first argument is NAN and the second argument is nonzero, then the result is NAN.
Syntax
pow(base, exponent)
Parameters
base |
Required. Specify the base. |
exponent |
Required. Specify the exponent. |
Return Value
Returns the base raise to the power of exponent.
Example:
In the example below, pow() function is used to calculate the base raised to the power of exponent.
<?php echo "pow(10, 2) = ".pow(10, 2)."\n"; echo "pow(5.2, 3) = ".pow(5.2, 3)."\n"; echo "pow(5.2, -3) = ".pow(5.2, -3)."\n"; echo "pow(5, NAN) = ".pow(5, NAN)."\n"; echo "pow(NAN, 2) = ".pow(NAN, 2)."\n"; echo "pow(2, INF) = ".pow(2, INF)."\n"; echo "pow(2, -INF) = ".pow(2, -INF)."\n"; ?>
The output of the above code will be:
ow(10, 2) = 100 pow(5.2, 3) = 140.608 pow(5.2, -3) = 0.0071119708693673 pow(5, NAN) = NAN pow(NAN, 2) = NAN pow(2, INF) = INF pow(2, -INF) = 0
❮ PHP Math Reference