I am dumping a database table....it has 4 columns and about 260 rows i would like for the each row in a set of 3 to be a different shade of grey row1 - grey row2 - light grey row3 - darkgrey repeat what the best way to accomplish this?
function get_color() { static $current = 0; static $colors = array( '#666666', '#999999', '#CCCCCC' ); return $colors[$current++ % sizeof($colors)]; } PHP: Set the colors in the function itself. As many as you want. And then in your loop just do: while (/* condition */) { $background = get_color(); // Do whatever with background } PHP:
that is amazing you know i know so crazy things, like how to grow alumina nanotube and attach proteins but sometimes the elegance in php amazes me thank you thank you and teach me teach me LOL
It was an interesting programming experience for me too. I was trying to keep the function as short as possible. It took me a moment to think of using the modulus operator.