Great example. I find recursive functions mostly useful for processing data sets with an unknown number of dimensions.

As for calculating the Fibonacci series using recursive functions, I think using straight loops would be a more elegant solution. Take the following recursive function for example..

function fibonacci ($n)
{
if ($n == 1 || $n == 2)
{
return 1;
}
else
{
return fibonacci($n – 1) + fibonacci($n – 2);
}
}

To find the 10th number in the Fibonacci sequence using this recursive function would take 109 iterations. However to find the same value using a straight while loop can be done in a measly 7.

function fibonacci($n)
{
$res = array(0, 1, 1);
if (isset($res[$n-1]))
{
return $res[$n-1];
} else
{
while (($a = sizeof($res)) < $n)
{
$res[] = $res[$a-1] + $res[$a-2];
}
}
return $res[$n-1];
}