Monday, May 23, 2016

How To Add Odd/Even Loop In Array Using PHP?

There are many ways to add odd/even loop in array using PHP. The most common and easy one I often use is the one below. With the help of following code, I can alternate the color of divs or tables or cell using odd and even classe.
$class = 'odd';  
for(.........) # no problem what kind of loop you are using(for,foreach,while,do)
   $class = ($class == 'even' ? 'odd' : 'even');
   #some code 



  1. Nice blog and very informative thank you for sharing us.
    Razorse Software