What is the best way to convert array like:
array(1,2,3,4,5,6,7,8,9,10)
to:
array(
array(1,2,3),
array(4,5,6),
array(7,8,9),
array(10),
);
I came up with something like:
$flat = array(1,2,3,4,5,6,7,8,9,10);
$colsLimit = 3;
$offset = 0;
$multi = array();
while($sliced = array_slice($flat, $offset, $colsLimit)) {
$multi[] = $sliced;
$offset += 3;
}
A better solutions are welcome.
array_slicedocumentation page