I need to print an array with menu items in 4 columns, sorted vertically, and filled out like this:

Here’s the markup structure to follow (5 items).
<ul>
<li>1</li>
<li>2</li>
</ul>
<ul>
<li>3</li>
</ul>
<ul>
<li>4</li>
</ul>
<ul>
<li>5</li>
</ul>
I’ve beeing trying something like this, but that doesnt work because it doesnt fill out the rows first, as the above example demonstrates:
$cols = 4;
$cnt = count($items);
echo "<ul>";
foreach($items as $i => $item) {
echo "<li>" . $item->ID . "</li>";
if(($i + 1)%$cols == 0 && ($i + 1) != $cnt) {
echo "</ul>\n<ul>";
}
}
echo "</ul>";
Any help on this is appreciated!
Something like this should do the trick for what you want to do. Simply input a data array and the number of columns desired, and it will separate that array into the specified number of columns
Just simply change the echo statements to wrap whatever HTML tags or whatever you want around it.
EDIT I fixed it. It now will work for any number of columns and input data. I have also made it into a function so it can be re-used many times.