note 23263 deleted from ref.strings by aidan
| From: | aidan@php.net | Date: | Tue, 28 Sep 2004 12:12:26 +0000 |
| Subject: | note 23263 deleted from ref.strings by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-77498@lists.php.net to get a copy of this message | ||
Note Submitter: chris at earleweb_nospam dot com
----
An alternative to the the "array_shift" way to change $color array:
$Counter = 0; //set to 1 if you want to start on #CCCCCC
$Colors = Array('#FFFFFF', '#CCCCCC');
$tableColor = $Colors[($Counter %= 2)];
/* $Counter %= 2; ensures $Counter is never greater than 1, in the off chance that you have a 32
thousand element array and really is not needed -- you could use $Counter % 2 if you really want
to*/
$Counter++;
When ever $Counter is odd the modulus division will leave 1, but even numbers (and 0) mod 2 = 0.
Then Counter is added to so that the next phase of the loop will become the next color.