Hi!
Could you please someone help me understand the solution of the following question?
Question:
What will be displayed when the following PHP code is executed:
<?php
function myFunc($value)
{
echo "its value is: $value";
}
echo "x is a variable, ";
myFunc(4);
?>
The answer is 16. The explanation that follows the answer is:
At first n=2, so we function goes into the else condition, and returns 2fun(3), the function again gets called, n equals 3 this time, so again goes into the else condition and returns 2fun(4), as n=4 this time it returns n which is now equal to 2 * 2 * 2 * 2 hence the answer being 16.
I’m a little bit lost here… I thought I understood how recursive functions work but I cannot figure out why n = 2 * 2 * 2 * 2.
Any help would be very much appreciated!!