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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.23 ms | 1395 KiB | 17 Q