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.
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
echo pow(2, -3); // Output: 0.125 (equivalent to 1/8)
$principal = 1000;
$rate = 0.05;
$years = 10;
$amount = $principal * pow(1 + $rate, $years);
echo $amount; // Output: 1628.89
echo pow(0, 3); // Output: 0
echo pow(3, 0); // Output: 1 (Any number raised to the power 0 is 1)
echo pow(16, 0.5); // Output: 4 (Equivalent to the square root of 16)
echo pow(2, 30); // Output: 1073741824
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.