(PHP 4, PHP 5, PHP 7, PHP 8)
pow —Exponential expression
Returnsnum
raised to the power ofexponent
.
Note:
It is possible to use the** operator instead.
num
The base to use
exponent
The exponent
num
raised to the power ofexponent
. If both arguments are non-negative integers and the result can be represented as an integer, the result will be returned withint type, otherwise it will be returned as afloat.
PHP-Extensions may override the behaviour of this operation and make it return an object.
Version | Description |
---|---|
8.4.0 | Raising0 to a negativeexponent is now deprecated. |
Example #1 Some examples ofpow()
<?php
var_dump(pow(2,8));// int(256)
echopow(-1,20),PHP_EOL;// 1
echopow(0,0),PHP_EOL;// 1
echopow(10, -1),PHP_EOL;// 0.1
var_dump(pow(newGMP("3"), newGMP("2")));// object(GMP)
echopow(-1,5.5);// NAN
?>
Note:
This function will convert all input to a number, even non-scalar values, which could lead toweird results.
Note that pow(0, 0) equals to 1 although mathematically this is undefined.