3v4l.org

run code in 300+ PHP versions simultaneously
<?php function custom_chunk($array, $maxrows) { $size = sizeof($array); $columns = ceil($size / $maxrows); $fullrows = $size - ($columns - 1) * $maxrows; for ($i = 0; $i < $maxrows; ++$i) { $result[] = array_splice($array, 0, ($i < $fullrows ? $columns : $columns - 1)); } return $result; } var_export(custom_chunk(range('a', 'r'), 12));

preferences:
27.83 ms | 402 KiB | 5 Q