Subscribe: Subscribe in NewsGator Online

Cycle

Cycling 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. :-)