<?php
function breakPartitionsLongerThan ($partitions, $length) {
$ret = array();
foreach ($partitions as $partition) {
$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]], 1));