Skip to content

Instantly share code, notes, and snippets.

@bgadrian
Created March 16, 2015 17:34
Show Gist options
  • Save bgadrian/ace4967f5c438fbf47fb to your computer and use it in GitHub Desktop.
Save bgadrian/ace4967f5c438fbf47fb to your computer and use it in GitHub Desktop.
PHP loop template {cycle}
<?php
//btools.eu PHP function to cycle array values (smarty {cycle} replacement)
function _bCycle(&$arr)
{
$v = next($arr);
if ($v === false)
return reset($arr);
return $v;
}
$table_colors = array('white','red','yellow');
//....for ...
echo '<tr style="background-color:'._bCycle($table_colors).'";>";
//easy as it gets ..
//array must have numbers or arrays, and not be empty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment