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']] = (isset($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 = 25
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 25
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 21
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/QNA7D
function name:  (null)
number of ops:  30
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, ->25
          8    > > FE_FETCH_R                                               $8, !3, ->25
   27     9    >   FETCH_DIM_R                                      ~9      !3, 'sn'
         10        FETCH_DIM_R                                      ~11     !3, 'sn'
         11        ISSET_ISEMPTY_DIM_OBJ                         0          !2, ~11
         12      > JMPZ                                                     ~12, ->21
         13    >   INIT_FCALL                                               'array_merge'
         14        FETCH_DIM_R                                      ~13     !3, 'sn'
         15        FETCH_DIM_R                                      ~14     !2, ~13
         16        SEND_VAL                                                 ~14
         17        SEND_VAR                                                 !3
         18        DO_ICALL                                         $15     
         19        QM_ASSIGN                                        ~16     $15
         20      > JMP                                                      ->22
         21    >   QM_ASSIGN                                        ~16     !3
         22    >   ASSIGN_DIM                                               !2, ~9
         23        OP_DATA                                                  ~16
   26    24      > JMP                                                      ->8
         25    >   FE_FREE                                                  $8
   30    26        INIT_FCALL                                               'var_dump'
         27        SEND_VAR                                                 !2
         28        DO_ICALL                                                 
         29      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.37 ms | 1396 KiB | 17 Q