3v4l.org

run code in 300+ PHP versions simultaneously
<?php $ary1 = array( array( 'sn' => '123', 'name' => 'whatever', ), array( 'sn' => '234', 'name' => 'whatever', ), ); $ary2 = array( array( 'sn' => '123', 'gender' => 'male', ), array( 'sn' => '234', 'gender' => 'female', ), ); $res = []; foreach (array_merge($ary1, $ary2) as $a) { $res[$a['sn']] = (count($res[$a['sn']])) ? array_merge($res[$a['sn']], $a) : $a; } var_dump($res);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 26
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 26
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 22
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/76BuQ
function name:  (null)
number of ops:  31
compiled vars:  !0 = $ary1, !1 = $ary2, !2 = $res, !3 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   14     1        ASSIGN                                                   !1, <array>
   25     2        ASSIGN                                                   !2, <array>
   26     3        INIT_FCALL                                               'array_merge'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $7      
          7      > FE_RESET_R                                       $8      $7, ->26
          8    > > FE_FETCH_R                                               $8, !3, ->26
   27     9    >   FETCH_DIM_R                                      ~9      !3, 'sn'
         10        FETCH_DIM_R                                      ~11     !3, 'sn'
         11        FETCH_DIM_R                                      ~12     !2, ~11
         12        COUNT                                            ~13     ~12
         13      > JMPZ                                                     ~13, ->22
         14    >   INIT_FCALL                                               'array_merge'
         15        FETCH_DIM_R                                      ~14     !3, 'sn'
         16        FETCH_DIM_R                                      ~15     !2, ~14
         17        SEND_VAL                                                 ~15
         18        SEND_VAR                                                 !3
         19        DO_ICALL                                         $16     
         20        QM_ASSIGN                                        ~17     $16
         21      > JMP                                                      ->23
         22    >   QM_ASSIGN                                        ~17     !3
         23    >   ASSIGN_DIM                                               !2, ~9
         24        OP_DATA                                                  ~17
   26    25      > JMP                                                      ->8
         26    >   FE_FREE                                                  $8
   30    27        INIT_FCALL                                               'var_dump'
         28        SEND_VAR                                                 !2
         29        DO_ICALL                                                 
         30      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
133.78 ms | 1396 KiB | 17 Q