I want to group items in a while loop (wrap multiple items in a div) so that first item is in one div, and rest of the items are in the set of 4 items in each div.
The problem is that the amount of the items varies. I have tried multiple ways using the if condition
within the loop, but the problem occurs if the number of items in the loop are more or less than expected. Then it just either misses or adds an additional div
For example, if I have 10 items, I'm trying to achieve this output:
<div class="group1">
item1
</div>
<div class="group2">
item2
item3
item4
item5
</div>
<div class="group3">
item6
item7
item8
item9
</div>
<div class="group4">
item10
</div>
How that can be done regardless
Use this :