- array_splice: documentation ( source)
- var_export: documentation ( source)
- ceil: documentation ( source)
- range: documentation ( source)
<?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));