You should use a for
loop instead of a foreach
loop like so:
for($i = 0; $i < count($children); $i+=2) {
$child1 = $children[$i];
$child2 = $children[$i+1];
// print both
}
if you may have an odd number of children you have to check if $i+1 < count($children)
before printing it.