Ok, so I have two arrays – one for posts, and a limited array of 5 values for the colors to give each post. What I want is for the posts to cycle through the array of colors, so that every 6th starts over. What I'm doing now works per se with a limited number of posts, but it's kind of hacky not very elegant:
$colors = array('yellow', 'red', 'blue', 'green', 'purple');
foreach($posts as $i => $post) {
$color = $colors[$i];
if ($i >= count($colors)) {
$color = $colors[-count($colors) + $i];
if ($i >= (count($colors) * 2)) {
$color = $colors[(-count($colors) * 2) + $i];
}
}
//Do stuff here
}
I'm sure there's a smarter way to do this, I just don't know how.