<?php $myPosts = range(1, 10); $i = null; $breakOn = 3; $rowStart = '<div class="row">' . "\n"; $rowEnd = '</div>' . "\n"; $item = ' <div class="item"></div>' . "\n"; while (array_shift($myPosts)) { if ($i === $breakOn) { echo $rowEnd . $rowStart; $breakOn = 5 - $breakOn; $i = 0; } elseif (!$i) { echo $rowStart; } echo $item; ++$i; } if ($i !== null) { echo $rowEnd; }
You have javascript disabled. You will not be able to edit any code.