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);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 14
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 16
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 14
Branch analysis from position: 42
Branch analysis from position: 14
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 16
Branch analysis from position: 37
Branch analysis from position: 16
filename:       /in/UZueA
function name:  (null)
number of ops:  46
compiled vars:  !0 = $array, !1 = $pairs, !2 = $i, !3 = $j
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   22     1        INIT_FCALL                                               'array_values'
          2        FETCH_DIM_R                                      ~5      !0, 'parent_id'
          3        SEND_VAL                                                 ~5
          4        DO_ICALL                                         $6      
          5        ASSIGN                                                   !0, $6
   24     6        INIT_FCALL                                               'usort'
          7        SEND_REF                                                 !0
          8        DECLARE_LAMBDA_FUNCTION                          ~8      [0]
          9        SEND_VAL                                                 ~8
         10        DO_ICALL                                                 
   26    11        ASSIGN                                                   !1, <array>
   27    12        ASSIGN                                                   !2, 0
         13      > JMP                                                      ->38
   28    14    >   ASSIGN                                                   !3, 0
         15      > JMP                                                      ->26
   29    16    >   FETCH_DIM_R                                      ~14     !0, !2
         17        FETCH_DIM_R                                      ~15     ~14, !3
         18        INIT_ARRAY                                       ~16     ~15
         19        ADD                                              ~17     !2, 1
         20        FETCH_DIM_R                                      ~18     !0, ~17
         21        FETCH_DIM_R                                      ~19     ~18, !3
         22        ADD_ARRAY_ELEMENT                                ~16     ~19
         23        ASSIGN_DIM                                               !1
         24        OP_DATA                                                  ~16
   28    25        PRE_INC                                                  !3
         26    >   INIT_FCALL                                               'min'
         27        FETCH_DIM_R                                      ~21     !0, !2
         28        COUNT                                            ~22     ~21
         29        SEND_VAL                                                 ~22
         30        ADD                                              ~23     !2, 1
         31        FETCH_DIM_R                                      ~24     !0, ~23
         32        COUNT                                            ~25     ~24
         33        SEND_VAL                                                 ~25
         34        DO_ICALL                                         $26     
         35        IS_SMALLER                                               !3, $26
         36      > JMPNZ                                                    ~27, ->16
   27    37    >   ASSIGN_OP                                     1          !2, 2
         38    >   COUNT                                            ~29     !0
         39        SUB                                              ~30     ~29, 1
         40        IS_SMALLER                                               !2, ~30
         41      > JMPNZ                                                    ~31, ->14
   32    42    >   INIT_FCALL                                               'print_r'
         43        SEND_VAR                                                 !1
         44        DO_ICALL                                                 
         45      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UZueA
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        COUNT                                            ~2      !1
          3        COUNT                                            ~3      !0
          4        SUB                                              ~4      ~2, ~3
          5      > RETURN                                                   ~4
          6*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.29 ms | 1008 KiB | 17 Q