3v4l.org

run code in 300+ PHP versions simultaneously
<?php function breakPartitionsLongerThan ($partitions, $length) { $ret = array(); $partition = call_user_func_array ('array_merge', $partitions); $chunks = array_chunk ($partition, $length); if (count($chunks) > 1) for ($i = 0; $i < count ($chunks) - 1; $i++) // for every chunk except the last one, append the first address of the next chunk. $chunks[$i][] = $chunks[$i+1][0]; $ret = array_merge ($ret, $chunks); return $ret; } var_dump (breakPartitionsLongerThan([[1,2,3,4,5],[6,7,8,9,10]], 6));

preferences:
53.36 ms | 402 KiB | 5 Q