Re: Recursion... Sort of...
| From: | Nathan Nobbe | Date: | Fri, 09 May 2008 15:32:01 +0000 |
| Subject: | Re: Recursion... Sort of... | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-274074@lists.php.net to get a copy of this message | ||
On Fri, May 9, 2008 at 1:52 AM, Stut <stuttle@gmail.com> wrote:
> 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.
in my haste i had also thought that would set the value to 0 every time the
function was called, heh.
-nathan