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

bookmark

<?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