1. Computing & Technology

Discuss in my forum

Pow () PHP Function

By , About.com Guide

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.

©2012 About.com. All rights reserved.

A part of The New York Times Company.