document.write('<div class="php" style="font-family: monospace;"><br />');
document.write('<span style="color: #000000; font-weight: bold;">&lt;?php</span><br />');
document.write('<span style="color: #808080; font-style: italic;">/**<br />');
document.write('&nbsp;* Use this to print alternating values from an array.<br />');
document.write('&nbsp;* It cycles through a series of values based on an iteration number.<br />');
document.write('&nbsp;* For example, you could use this for alternating background colors.<br />');
document.write('&nbsp;*/</span><br />');
document.write('<span style="color: #000000; font-weight: bold;">Class</span> Cycle <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0000ff;">$options</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0000ff;">$num_options</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0000ff;">$idx</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; public <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">options</span> = <a target="_blank"&nbsp; href="http://www.php.net/func_get_args"><span style="color: #000066;">func_get_args</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">num_options</span> = <a target="_blank"&nbsp; href="http://www.php.net/count"><span style="color: #000066;">count</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">options</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> <a target="_blank"&nbsp; href="http://www.php.net/is_array"><span style="color: #000066;">is_array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">options</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">options</span> = <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">options</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">num_options</span> = <a target="_blank"&nbsp; href="http://www.php.net/count"><span style="color: #000066;">count</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">options</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">idx</span> = <span style="color: #cc66cc;">0</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; public <span style="color: #000000; font-weight: bold;">function</span> __toString<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$ret</span> = <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">options</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">idx</span>++<span style="color: #66cc66;">&#93;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">idx</span> &gt;= <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">num_options</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">idx</span> = <span style="color: #cc66cc;">0</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$ret</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />');
document.write('<span style="color: #66cc66;">&#125;</span><br />');
document.write('<br />');
document.write('<span style="color: #808080; font-style: italic;">//usage</span><br />');
document.write('<span style="color: #0000ff;">$cycle</span> = <span style="color: #000000; font-weight: bold;">new</span> Cycle<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">\'red\'</span>,<span style="color: #ff0000;">\'green\'</span>,<span style="color: #ff0000;">\'blue\'</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('<a target="_blank"&nbsp; href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$cycle</span>; <span style="color: #808080; font-style: italic;">//red</span><br />');
document.write('<a target="_blank"&nbsp; href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$cycle</span>; <span style="color: #808080; font-style: italic;">//green</span><br />');
document.write('<a target="_blank"&nbsp; href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$cycle</span>; <span style="color: #808080; font-style: italic;">//blue</span><br />');
document.write('<a target="_blank"&nbsp; href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$cycle</span>; <span style="color: #808080; font-style: italic;">//red</span><br />');
document.write('<span style="color: #808080; font-style: italic;">//outputs redgreenbluered</span><br />');
document.write('<span style="color: #000000; font-weight: bold;">?&gt;</span><br />');
document.write('&nbsp;</div>');
document.write('<br />&nbsp;<br /><div style="font-size: 12px">Brought to you by the community at <a href="http://www.bytemycode.com/snippets/snippet/746/1/" target="_blank">byteMyCode</a>.</div>');
