Possible Duplicate:
Slice an array into 4 other arrays
An array can be split into 3 smaller arrays using:
$things = array('...'); // an array containing 9 things
$things = array_chunk($things, count($things)/3);
Problem: However when count($things) the number of items in the array cannot be divided equally by 3, I end up with 4 smaller arrays. Example, if I have 10 elements in array $things, inputting it into array_chunk() gives me 3 arrays of 3 elements, and a 4th array containing 1 element.
How can I divide an array into 3 smaller arrays, such that if I have a situation like in the example above, I will end up with
count($things[0]) == 4
count($things[1]) == 4
count($things[2]) == 2
Bascially what I am doing is to take a big array and display it as equally as possible into 3 columns. It’s alphabetically sorted, so sequence is important.
Try
ceil(count($things) / 3), so the split point is rounded up. that’d give you (say) 4/4/3 instead of 3/3/3/2 for an 11-item array.