Created
March 16, 2015 17:34
-
-
Save bgadrian/ace4967f5c438fbf47fb to your computer and use it in GitHub Desktop.
PHP loop template {cycle}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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