This PHP snippet shows 2 methods for displaying alternative row colors while looping through an array. In the examples listed here only the font colors are changed. In reality you can change anything you like based on the outcome of the calculations.
<?php
// method 1
$a = array ('one','two','three','four');
foreach ($a as $b => $c) {
$color = ( is_int($b / 2) ) ? 'red' : 'blue';
echo '<span style="color: '. $color .'">'. $c .'</span><br />'."\n";
}
// method 2 - no need to know: use counter
$i = 0;
foreach ($a as $b => $c) {
$color = ( ++$i & 1 ) ? 'red' : 'blue';
echo '<span style="color: '. $color .'">'. $c .'</span><br />'."\n";
}