3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $data = range(1,7); $limit = 3; $point = count($data)-count($data)%$limit; $result = array_chunk(array_slice($data, 0, $point), $point/$limit); $result[$limit-1] = array_merge($result[$limit-1], array_slice($data, $point)); var_dump($result);
Output for 4.3.0 - 5.6.25, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(3) { [0]=> array(2) { [0]=> int(1) [1]=> int(2) } [1]=> array(2) { [0]=> int(3) [1]=> int(4) } [2]=> array(3) { [0]=> int(5) [1]=> int(6) [2]=> int(7) } }