The pow() function takes two parameters: a base and a power to raise it by.
PHP pow() Function has the following syntax.
number pow ( number base, number exponent )
Parameter | Is Required | Description |
---|---|---|
base | Required. | Base to use |
exponent | Required. | Exponent |
Item | Value |
---|---|
Return Value | x raised to the power of y |
Return Type | Integer if possible, Float otherwise |
You can send negative powers for the second parameter to pow() to generate roots. And the parameters need not be integers.
<?php/*from w ww .ja v a 2s . co m*/
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.