View Single Post

  #8 (permalink)  
Old 05-09-2008
Matt Neimeyer
 
Posts: n/a
Default Re: [PHP] Recursion... Sort of...

Wow! Thanks guys! Here's what I ended up doing... To get...

Black on White - 1
White on Black - 2
Black on White - 3
Black on White - 3
White on Black - 2
Black on White - 3

I had to do something like...


function doStuff()
{
static $callCount = 0;
$callCount++;

if($callCount%2)
{ echo 'white on black - '.$callCount; }
else
{ echo 'black on white - '.$callCount; }

// Stuff that uses the depth count

$callCount--;
}

If I didn't put in the $callCount--; I ended up with something like this...

Black on White - 1
White on Black - 2
Black on White - 3
White on Black - 4
Black on White - 5
White on Black - 6

I saw where it was said that "oh he said it wasn't recursive"... Sorry
I wasn't clearer. In my mind a "true" recursive function is a function
that operates on it's own output like a factorial... Not just a
function that is called inside itself.

This got me where I needed to be and it is GREATLY appreciated!

Matt
Reply With Quote