# PHP program to calculate the power of a given number using recursion

Here, we are going to learn how to calculate the power of a given number using recursion in PHP?
Submitted by Nidhi, on November 19, 2020

In this program, we will calculate the power of the specified given number using recursion.

The power 3 of number 5 is 125.

Program/Source Code:

The source code to calculate the factorial of a given number using recursion is given below. The given program is compiled and executed successfully.

```<?php
//PHP program to calculate the power of a number
//using recursion.
function Power(\$num, \$p)
{
if (\$p == 0) return 1;
return \$num * Power(\$num, \$p - 1);
}

\$result = Power(5, 3);
echo "Result is: " . \$result;
?>
```

Output:

```Result is: 125
```

Explanation:

In the above program, we created a recursive function Power() to calculate the power of a given number, The Power() function returns the power of a specified number to the calling function, in our program, we calculated the power 3 of number 5 that is 125.

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates