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/*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.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions