I'm using the following working code to wrap every 3 elements in a div:
$count = 1
foreach( $names as $name ):
if ($count%3 == 1) {
echo '<div class="wrap">';
}
echo $name;
if ($count%3 == 0) {
echo '</div>';
}
$count++;
endforeach;
if ($count%3 != 1) echo "</div>";
That returns:
<div class="wrap">
name
name
name
</div>
<div class="wrap">
name
name
name
</div>
<div class="wrap">
name
name
name
</div>
<div class="wrap">
name
name
name
</div>
So far so good.. but i want the second wrapped set to have 4 "name" elements like so:
<div class="wrap">
name
name
name
</div>
<div class="wrap">
name
name
name
name
</div>
<div class="wrap">
name
name
name
</div>
<div class="wrap">
name
name
name
</div>
Every 3 items should be wrapped in the div, except the second set which will have 4 items.
Or another way to explain: items 4 to 8 will be wrapped in a div while every other 3 items will be wrapped in div.
How can this be achieved?