Well essentially the remainder of a division of the number by the second number. Because of odd and even numbers, every other number (integer) can be divided perfectly by 2, which provides the alternating colours.
This is a nice variation building in the integer increment, others follow the same principle:
PHP Code:
$i = 0;
while ( some condition/collects data ) {
if ($%2) {$bg = "#0E377C";} else {$bg = "#266BB1";}
$i++;
}
Using ternary operator:
PHP Code:
$i = 0;
while ( some condition/collects data ) {
$bg = ( ($i++ % 2) ? "#0E377C" : "#266BB1" );
}
Bookmarks