Easiest way to alternate row colors in PHP/HTML?

Posted by thrashr888 on Stack Overflow See other posts from Stack Overflow or by thrashr888
Published on 2008-12-29T23:56:38Z Indexed on 2010/06/14 7:32 UTC
Read the original article Hit count: 126

Filed under:
|
|
|

Here's a PHP example of mine. Can anyone find a shorter/easier way to do this?

<? foreach($posts as $post){?>
    <div class="<?=($c++%2==1)?‘odd’:NULL?>">
    	<?=$post?>
    </div>
<? }?>

<style>
    .odd{background-color:red;}
</style>

Examples in other languages would be fun to see as well.

© Stack Overflow or respective owner

Related posts about php

Related posts about html