I have an array of unknown length:
$array = array('1', '2', '3', '4', '5', '6', '7', '8' ...);
I need to output this array as multiple lists, where a new list is created for every 3 array entries.
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
<ul>
<li>4</li>
<li>5</li>
<li>6</li>
</ul>
<ul>
<li>7</li>
<li>8</li>
</ul>
Note that I need to close the last list even if it does not contain 3 list-items.
Here is my attempt:
<?php for ($i = 0; $i < count($rows); ++$i): ?>
<?php if (($i % 3) == 0): ?>
<ul>
<?php endif; ?>
<li><?php print $rows[$i]; ?></li>
<?php if (($i % 3) == 2): ?>
</ul>
<?php endif; ?>
<?php endfor; ?>