- array_map: documentation ( source)
- var_dump: documentation ( source)
- array_chunk: documentation ( source)
- array_fill: documentation ( source)
<?php
$array = [1,2,3,4,5];
$cols = 4;
$chunks = array_fill(0, $cols, []);
$cnt = 0;
foreach ($array as $thing) {
$chunks[$cnt++ % $cols][] = $thing;
}
var_dump($chunks);
$chunks2 = array_map(null, ...array_chunk($array, $cols));
var_dump($chunks2, $chunks2 === $chunks);