[thelist] recursive PHP functions

Rob Wilson robw at enigma-interactive.co.uk
Mon Sep 16 11:00:01 CDT 2002


That should read

<?php
function recursive ($n)
{
   	if ($n > 10)
   	{
   		return $n;
	}
	echo "N =" . $n . "<BR>";
	$n++;
	return recursive ($n);
}
echo "The result:".recursive(1)."<br>";
?>

With the important line being the :

return recursive ( $n );

This allows you to unwind the recursion correctly.

HTH

Rob



More information about the thelist mailing list