Re: [PHP] Recursion... Sort of...

[email protected] ("Matt Neimeyer")
Newsgroups php.general
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.