PHP pow() Function

In this chapter you will learn:

  1. Definition for PHP pow() Function
  2. Syntax for PHP pow() Function
  3. Parameter for PHP pow() Function
  4. Return for PHP pow() Function
  5. Example - Raise to the power

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/*  j a  v  a 2s.com*/
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.

Next chapter...

What you will learn in the next chapter:

  1. Definition for PHP rad2deg() Function
  2. Syntax for PHP rad2deg() Function
  3. Parameter for PHP rad2deg() Function
  4. Return for PHP rad2deg() Function
  5. Example - Convert radians to degrees