1. Home
  2. Computing & Technology
  3. PHP / MySQL

Pow () PHP Function

By Angela Bradley, About.com

Definition: In mathematics, an exponent is used to take a number and multiply it by itself a certian a number of times. For example 4^5 (four to the power of five) would be 4*4*4*4*4, or 1024. We can do the same thing in PHP using the pow () function. It is written as pow(base, power) ; Our previous example of 4^5 would be written as pow (4, 5) ;
Examples:
<?php
echo pow(5, 3) ;
echo "<br>";
echo pow(-3, 3) ;
echo "<br>";
echo pow(2, 4) ;
?>
This would output:
125
-27
16
Please note that while this will most likely work for you, older versions of PHP have trouble using negative bases, and need some manipulation to work. They will return false.
Explore PHP / MySQL
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. PHP Functions
  5. PHP Exponent - PHP Power Of - PHP Raised Power

©2009 About.com, a part of The New York Times Company.

All rights reserved.