PHP Math functions pow

echo pow(2,3); // ouptut 8
Using variables
$a=3; 
$b=4; 
echo pow($a,$b); // output 81
Syntax
pow(base, exponent)
We get output as base raised to the power of exponent.

Example

We can create a square table by using for loop
for($i=1;$i<=10;$i++){
echo $i. "=".pow($i,2)."<br>";
}
Output is here
1=1
2=4
3=9
4=16
5=25
6=36
7=49
8=64
9=81
10=100

Example: Negative Exponents

echo pow(2, -3);  // Output: 0.125 (equivalent to 1/8)

Example: Compound Interest Calculation

$principal = 1000;
$rate = 0.05;
$years = 10;
$amount = $principal * pow(1 + $rate, $years);
echo $amount;  // Output: 1628.89

Example: Powers of Zero

echo pow(0, 3);  // Output: 0
echo pow(3, 0);  // Output: 1 (Any number raised to the power 0 is 1)

Example: Fractional Exponents (Square Root)

echo pow(16, 0.5);  // Output: 4 (Equivalent to the square root of 16)

Example: Large Exponents

echo pow(2, 30);  // Output: 1073741824

How pow is used with sqrt function to get hypotenuse of a triangle

Math Functions base_convert(): Convert number From any base to other decbin() Binary equivalent of decimal number dechex(): Convert decimal number to hexadecimal system
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    Post your comments , suggestion , error , requirements etc here





    PHP video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer