PHP pow() Function
Definition
The pow() function takes two parameters: a base and a power to raise it by.
Syntax
PHP pow() Function has the following syntax.
number pow ( number base, number exponent )
Parameter
Parameter | Is Required | Description |
---|---|---|
base | Required. | Base to use |
exponent | Required. | Exponent |
Return
Item | Value |
---|---|
Return Value | x raised to the power of y |
Return Type | Integer if possible, Float otherwise |
Example
You can send negative powers for the second parameter to pow() to generate roots. And the parameters need not be integers.
<?php/*w ww .j av a 2 s . c om*/
print pow(10,2); // 100
print "\n";
print pow(-10, 4); // 10000
print "\n";
print pow(10, -1);
print "\n";
print pow(10, -2);
print "\n";
print pow(10.1,2.3);
print "\n";
echo( pow(2,4) );
print "\n";
echo(pow(-2,4));
print "\n";
echo(pow(-2,-4));
print "\n";
echo(pow(-2,-3.2));
?>
The code above generates the following result.