3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array( array( 'id' => 1, 'user_name'=>'test1' ), array( 'id' => 2, 'user_name'=>'test2' ), array( 'id' => 3, 'user_name'=>'test3' ) ); $arr2 = array( array( 'id' => 1, 'shop_name'=>'shop1' ), array( 'id' => 5, 'shop_name'=>'shop2' ), array( 'id' => 3, 'shop_name'=>'shop3' ) ); /*function filter($item) { return count($item) == 3 ? $item :false; } $newArr = array_filter(array_merge($arr, $arr2), 'filter'); print_r($newArr); foreach($arr as $key => &$value) { //$value['shop_name']=''; } unset( $value ); foreach($arr as $k2 =>&$v2) {$v2['shop_name']=''; foreach($arr2 as $k =>$v) { if($v2['id'] == $v['id']) { $v2['shop_name'] = $v['shop_name']; } } } print_r($arr);*/ $user_name = array_column($arr, 'user_name', 'id'); $shop_name = array_column($arr, 'shop_name', 'id'); $arr = []; foreach($user_name as $id => $user) { $temp = ['id'=>$id, 'user_name'=>$user, 'shop_name'=>'']; if(array_key_exists($id, $shop_name)) $temp['shop_name'] = $shop_name[$id]; $arr[] = $temp; } print_r($arr);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 30
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 30
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 27
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 27
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/VBtDI
function name:  (null)
number of ops:  35
compiled vars:  !0 = $arr, !1 = $arr2, !2 = $user_name, !3 = $shop_name, !4 = $user, !5 = $id, !6 = $temp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   17     1        ASSIGN                                                   !1, <array>
   50     2        INIT_FCALL                                               'array_column'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 'user_name'
          5        SEND_VAL                                                 'id'
          6        DO_ICALL                                         $9      
          7        ASSIGN                                                   !2, $9
   51     8        INIT_FCALL                                               'array_column'
          9        SEND_VAR                                                 !0
         10        SEND_VAL                                                 'shop_name'
         11        SEND_VAL                                                 'id'
         12        DO_ICALL                                         $11     
         13        ASSIGN                                                   !3, $11
   52    14        ASSIGN                                                   !0, <array>
   53    15      > FE_RESET_R                                       $14     !2, ->30
         16    > > FE_FETCH_R                                       ~15     $14, !4, ->30
         17    >   ASSIGN                                                   !5, ~15
   54    18        INIT_ARRAY                                       ~17     !5, 'id'
         19        ADD_ARRAY_ELEMENT                                ~17     !4, 'user_name'
         20        ADD_ARRAY_ELEMENT                                ~17     '', 'shop_name'
         21        ASSIGN                                                   !6, ~17
   55    22        ARRAY_KEY_EXISTS                                         !5, !3
         23      > JMPZ                                                     ~19, ->27
         24    >   FETCH_DIM_R                                      ~21     !3, !5
         25        ASSIGN_DIM                                               !6, 'shop_name'
         26        OP_DATA                                                  ~21
   56    27    >   ASSIGN_DIM                                               !0
         28        OP_DATA                                                  !6
   53    29      > JMP                                                      ->16
         30    >   FE_FREE                                                  $14
   59    31        INIT_FCALL                                               'print_r'
         32        SEND_VAR                                                 !0
         33        DO_ICALL                                                 
         34      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.92 ms | 1396 KiB | 17 Q