Soldato
I'm using PHP and an array to print HTML divs in rows of 3s for a grid-layout. The code is basically this, less the array content:
What I want is for the foreach() to break so that the last row of the grid contains a full 3, rather than 1 or 2, effectively dropping the last 1 or 2 contents of the array.
I could do a clunky solution where I count the array, divide it by 3, then count the rows as they get created in the foreach() and break it based on that but that seems longwinded.
What's a neater solution?
Code:
<div class="row ht3" data-aos="fade-up">
<?php
$divcount = 0;
foreach ($work as $value){
print "$value \n";
$divcount = $divcount + 1;
if($divcount % 3 == 0){
?>
</div>
<div class="row ht3" data-aos="fade-up">
<?php
}
}
?>
</div>
What I want is for the foreach() to break so that the last row of the grid contains a full 3, rather than 1 or 2, effectively dropping the last 1 or 2 contents of the array.
I could do a clunky solution where I count the array, divide it by 3, then count the rows as they get created in the foreach() and break it based on that but that seems longwinded.
What's a neater solution?