3v4l.org

run code in 200+ PHP versions simultaneously
<?php function double_chunk($array, $maxrows) { $size = sizeof($array); $columns = ceil($size / $maxrows); $fullrows = $size - ($columns - 1) * $maxrows; if ($fullrows == $maxrows) { return array_chunk($array, $fullrows); // all columns have full rows, don't splice } return array_merge( array_chunk( array_splice($array, 0, $columns * $fullrows), $columns ), array_chunk($array, $columns - 1) ); } var_export(double_chunk(range('a', 'i'), 3));
based on aAeYi
Output for 5.6.38 - 7.4.0
array ( 0 => array ( 0 => 'a', 1 => 'b', 2 => 'c', ), 1 => array ( 0 => 'd', 1 => 'e', 2 => 'f', ), 2 => array ( 0 => 'g', 1 => 'h', 2 => 'i', ), )