PHP pow() Function

The pow() function is used to compute the power of a certain number. It returns xy calculation, also termed as x raised to y. PHP also provides "**" as an exponentiation operator.

So, pow(x,y) returns xy which is same as x**y

Syntax

pow ( number $base , number $exp ) : number

Parameters

Sr.No Parameter & Description
1 base
The base to be raised
2 exp
Power to which base needs to be raised

Return Value

PHP pow() function returns base raised to power of exp. If both arguments are non-negative integers, the result is returned as integer, otherwise it is returned as a float.

Examples

Basic Power Calculation

Calculate area of a circle using pow() function ?

<?php
    $radius = 5;
    echo "radius = " . $radius . " area = " . M_PI * pow($radius, 2);
?>
radius = 5 area = 78.539816339745

Different Data Types

Demonstrating pow() with different numeric types ?

<?php
    echo "2^3 = " . pow(2, 3) . "<br>";
    echo "2.5^2 = " . pow(2.5, 2) . "<br>";
    echo "9^0.5 = " . pow(9, 0.5) . "<br>";
    echo "4^-1 = " . pow(4, -1);
?>
2^3 = 8
2.5^2 = 6.25
9^0.5 = 3
4^-1 = 0.25

Comparison with ** Operator

Both pow() function and ** operator produce the same results ?

<?php
    $base = 3;
    $exp = 4;
    
    echo "Using pow(): " . pow($base, $exp) . "<br>";
    echo "Using **: " . ($base ** $exp);
?>
Using pow(): 81
Using **: 81

Conclusion

The pow() function is essential for mathematical calculations in PHP, supporting both integer and float operations. For simple cases, the ** operator provides a more readable alternative.

Updated on: 2026-03-15T08:58:36+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements