Answer the question
In order to leave comments, you need to log in
How is this function performed?
Can you please tell me how this recursive function is performed, raising a number to a power?
<?php
function myRecursion($x, $n) {
if ($n == 0) {
return 1;
}
if ($n < 0) {
return myRecursion(1/$x, -$n);
}
return $x * myRecursion($x, $n-1);
}
var_dump(myRecursion(5, 3));
?>
return $x * myRecursion($x, $n-1);
Answer the question
In order to leave comments, you need to log in
how is this recursive function performed, raising a number to a power?
After adjusting $n to zero and the function returns 1, what happens?
why write myRecursion($x, $n-1) and not myRecursion($n-1)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question