[thelist] recursive PHP functions

Jay Blanchard jay.blanchard at niicommunications.com
Mon Sep 16 10:41:01 CDT 2002


ooops
[snip]
function recursive ($n)
 {
    if ($n > 10) return $n;
	$n++;
	recursive ($n);
 }
echo "The result:".rec1(1)."<br>";
[/snip]

Read it too fast ...

If $n greater than 10 it returns $n. If $n is less than 10 it would then
increment the number and then attempt to call the function again. If it
succeeds it would loop through until $n becomes 11, at which time it would
exit. I don't know that you can call the functions again from within the
function. There are other ways to write this.

HTH!

Jay






More information about the thelist mailing list