sorry for the very stupid question. It seems to be more of a logical problem than a programming one, but whatever.
So i have this nice array that I want to output in html and I wnt to split it in groups of three elements.
<DIV>
product1
product2
product3
</DIV>
<DIV>
product4
</DIV>
this is my code
$counter = 0;
foreach ($prods as $prod) {
if($counter == 0 || ($counter % 3) == 0) {
$htm_l .= '<div data-count="' . $counter . '">';
}
$htm_l .= '<br> PROD' . $counter;
$counter++;
if($counter == 0 || ($counter % 3) == 0) {
$htm_l .= '</div>';
}
}
Of course it produces wrong results like:
<div data-count="0">
<br> PROD0
<br> PROD1
<br> PROD2
</div>
<div data-count="3">
<br> PROD3
Missing a closing div. What is a clean way to achieve my result? Thanks in advance