PHP easiest color swap for rows

<style> 

.odd{background-color:red;} 

</style> 

$c = true;

foreach($posts as $post) echo '<div'.(($c = !$c)?' class="odd"':'').">$post</div>";

Source: https://stackoverflow.com/questions/399137/easiest-way-to-alternate-row-colors-in-php-html

Back to Top