Hey guys, I'm trying to convert my recursive function from one that echos out its output to one that buffers the output for later use.
Here's the general structure of the function. I've left out the generic stuff and just left the core of the recursion. What am I missing?
<?PHP
function doSomething($parent, $variable) {
if ($parent > 0)
// The twolines below are fake
$main_output = "something $variable";
$main_output .= $parent * $variable;
return $main_output . doSomething($parent-2, $variable+1);
}
}
$total_menu_output = doSomething(10,10);
?>
<HTML>
stuff
<?=$total_main_output?>
</HTML>
But when I spit out the contents of $total_main_output, it contains only a fraction of the code that should be there. I realize that this code doesn't really make sense - I'm just checking if there's some inherent error in the way i've set up the function.
The function worked nicely when I had echo "something $variable" instead of $main_output = "something $variable". But once I added in these new things, the output seems to indicate that only the outermost instance of the function is being captured.
Any thoughts or rewritings or my function would be useful.
-Aaron