A Basic Case of Code Rabies
Here's a simple little script that will produce alternating colors. This isn't anything amazing nor unique. There are quite a lot of ways to do it on google that are not extremely simple. And it's a really good introduction to the little-used modulus (%) operator.
I'll assume you have 2 CSS classes with the colors you want to use: .odd and .even.
Proceed with the code rabies!
$array = array("a" => "derp", "b" => "derp", ...) $ticker = 1; foreach ($array as $key => $value) { $class = $ticker%2 == 0 ? "odd" : "even"; echo "<div class = '".$class."'></div>" $ticker++; }














