I have a responsive page where i have images as set. But my problem is simple, if there are 10 pictures, i should echo 3 items in one row, in total 3 rows like that as one of them is width 33% width, and the lonely one, must have 100% width. or if there is 11 pictures, 3 rows with 3 images with width 33%, one row with %50 and %50 two images. How can i effectly do that in PHP, not with too many if statements ?
<?php if (count($pictures)): ?>
<?php foreach ($pictures as $picture): ?>
<div class="u-1-3"> <!-- means %33 width, u-2-3 is %66 width and u-3-3 is 100% width -->
<aside class="caption">
<?=$picture->title;?>
</aside>
</div>
<?php endforeach; ?>
<?php endif; ?>
I would suggest using your current loop with the array_chunk method.
$pictureChunk = array_chunk($pictures, 3);