|  Please subscribe to the blog if you haven't already

Cycling through a list of strings

Needing to cycle through a list ( array ) of strings is a common need. Particularly when you want to flip flop through colors on table rows. Rather than custom program the logic in every script I run I encapsulated it in a simple class. The class name is “cycle”.

The class has three methods:

  • load: This function takes a string and adds it to its internal list
  • getNext: returns the next string on the list and returns the first string if at the end of the list.
  • reset_pointer: sets getNext to return the first string on the list.

The code is for php5.

Feel free to use it, extend it, or mock it often. :-)


Like it? Subscribe to the blog if you haven't already
Filed under: General, Web Technologies — Scott @ November 1, 2005 10:10 am Sphinn Digg!

Comments »

No comments yet.

Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.