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

[email protected] (Stut)
Newsgroups php.general
Message-ID <[email protected]>
On 9 May 2008, at 02:02, Nathan Nobbe wrote:
> function doStuff() {
> static $callCount;
>
> if(!isset($callCount))
>  $callCount = 1;
> else
>   $callCount++;
>
> /// do stuff w/ $callCount to potentially handle sub-tabs and stuff
>    if($callCount == 2) {
>      echo 'white on black';
>    } else {
>      echo 'black on white';
>    }
>    echo PHP_EOL;
> }

No need for the first if, just give the static var a default value...

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

Much neater.

-Stut

-- 
http://stut.net/
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.