note 23263 added to ref.strings
| From: | chris at earleweb_nospam dot com | Date: | Sat, 13 Jul 2002 06:03:47 +0000 |
| Subject: | note 23263 added to ref.strings | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-33015@lists.php.net to get a copy of this message | ||
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.
--
http://www.php.net/manual/en/ref.strings.php
http://master.php.net/manage/user-notes.php?action=edit+23263
http://master.php.net/manage/user-notes.php?action=delete+23263
http://master.php.net/manage/user-notes.php?action=reject+23263