Super-short PHP Even / Odd Alternator


/ Published in: PHP
Save to your folder(s)

Use this to add alternating rows in PHP.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.