Alternate row colors programming in php


Alternating colors in php, it's simple. Here is the code:

foreach( $array_values as $value )
$background_color = ( $counter % 2 == 0 ) ? ('blue') : ('red');echo '' . $value . '';

As you can see it's simple. If the current row number is even the color is blue, if the row number is odd, background color is red. This is just an example, you can alternate what colors you want using php. $array_values array can be an array coming from a database query.