<?php
$arr = array(1,1,1,4,4,7,3);
$old_value = 0;
$colour = 'blue';
echo '<table>';
foreach ($arr as $key => $value)
{
 if ($old_value == $value)
 {
 //colour stays the same
 }
 else
 {
 if($colour == 'blue')
 {
 $colour = 'yellow';
 }
 else
 {
 $colour = 'blue';
 }
 $old_value = $value;
 }
 echo '<tr style="background-color:' .$colour . '"><td>' . $value . '</td></tr>'; 
}
echo '</table>';
?>
Advertisements