Original Post
I am curious I was asked a question today that just irks me cause I didn't know the answer and I blanked out. Here is a sample code that I wrote to show you. There are tons of examples on it anyways I just can't seem to find the answer.
[source]
function factorial($factor)
{
$temp;
if ($factor <= 1)
return 1;
return $temp = $factor * factorial($factor - 1);
}
// Example use
echo factorial(3);
[/source]
Doesn't really matter what language as long as it allows you to call the function in its function.
Anyways the question was what is the advantage and disadvantage of using this... I froze so bad! Anyone able to explain this to me there was no over the other. I can write it in a different language if you don't understand it, but I am sure that won't be the issue. Thanks in advance.
[source]
function factorial($factor)
{
$temp;
if ($factor <= 1)
return 1;
return $temp = $factor * factorial($factor - 1);
}
// Example use
echo factorial(3);
[/source]
Doesn't really matter what language as long as it allows you to call the function in its function.
Anyways the question was what is the advantage and disadvantage of using this... I froze so bad! Anyone able to explain this to me there was no over the other. I can write it in a different language if you don't understand it, but I am sure that won't be the issue. Thanks in advance.