3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array ( 'parent_id' => array ( 9 => array ( 0 => 12 ), 20 => array ( 0 => 25, 1 => 22 ), 21 => array ( 0 => 23, 1 => 24 ) ) ); // re-index to 0 $array = array_values($array['parent_id']); // sort so the longest arrays are first usort($array, function ($a, $b) { return count($b) - count($a); }); // output array $pairs = array(); for ($i = 0; $i < count($array) - 1; $i += 2) { for ($j = 0; $j < min(count($array[$i]), count($array[$i+1])); $j++) { $pairs[] = array($array[$i][$j], $array[$i+1][$j]); } } print_r($pairs);

preferences:
25.3 ms | 407 KiB | 5 Q