/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function cycle(/*$val1, $val2, $valN*/) { static $counter = 0; if ($length == 0) { $counter = 0; return null; } return $values[$counter++ % $length]; } // example usage $i = 0; while ($i++ < 5) { echo cycle('odd','even') . '<br>'; } cycle(); // reset $i = 0; while ($i++ < 6) { echo cycle('a','b','c','d') . '<br>'; } /* output => odd even odd even odd a b c d a b */