PHP Tutorial - 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

ParameterIs Required Description
baseRequired. Base to use
exponentRequired. Exponent

Return

Item Value
Return Valuex 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/*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.