I am having trouble working out the logic for what I need to achieve
On the web page I have a dynamically generated array from a set of results. The array count can be any number. For example on one page there could be 11 items whereas on another 211.
What I need is to split this into 3 columns and 3 UL's.
Lets say the array holds 23 items, The desired output would be:
<div class="column">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
<li>Item 6</li>
<li>Item 7</li>
<li>Item 8</li>
</ul>
</div>
<div class="column">
<ul>
<li>Item 9</li>
<li>Item 10</li>
<li>Item 11</li>
<li>Item 12</li>
<li>Item 13</li>
<li>Item 14</li>
<li>Item 15</li>
<li>Item 16</li>
</ul>
</div>
<div class="column">
<ul>
<li>Item 17</li>
<li>Item 18</li>
<li>Item 19</li>
<li>Item 20</li>
<li>Item 21</li>
<li>Item 22</li>
<li>Item 23</li>
</ul>
</div>
Where the items are in order, and they are split as equally as possible. If there is an odd number, that is fine as the last column will be less as shown above.
I have tried using the array_chunk()
$ar_list = array("<li>Item 1</li>","<li>Item 2</li>","<li>Item 3</li>","<li>Item 4</li>","<li>Item 5</li>");
$lists = array_chunk($ar_list, 3);
foreach ($lists as $list) {
echo '<ul>';
echo $list;
echo '</ul>';
}
However, this returns:
Array
Array
Array
Array
Array
Can someone please help me get the contents of: $ar_list to output like the desired effect?
Thank you in advance