<?php $array = range(1, 65); $minColumns = 9; $count = count($array); $maxRows = intdiv($count, $minColumns); $maxColumns = ceil($count / $maxRows); $longRowsCount = $count % $maxRows; echo "$count, $maxRows, $maxColumns, $longRowsCount\n"; var_export([ ...array_chunk( array_splice( $array, 0, ($maxColumns * $longRowsCount) ?: $count ), $maxColumns ), ...array_chunk($array, $maxColumns - 1) ]);
You have javascript disabled. You will not be able to edit any code.