Posted By

mindshare on 06/02/11


Tagged

css rows Ternary Modulo alternate modulus


Versions (?)

Super-short PHP Even / Odd Alternator


 / Published in: PHP
 

Use this to add alternating rows in PHP.

  1. $i = 0;
  2. // start loop
  3. $alt = ($i%2) ? 'even' : 'odd';
  4. // echo the result, etc
  5. $i++;
  6. // end loop
  7.  
  8. /* usage:
  9.  - place inside a loop
  10.  - increment the $i variable at the end of the loop
  11. */

Report this snippet  

You need to login to post a comment.