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);*/ $shop_name = array(); foreach($arr2 as $item) $shop_name[$item['id']] = $item['shop_name']; foreach($arr as $key => $item) { $exist = array_key_exists($item['id'], $shop_name); $arr[$key]['shop_name'] = $exist ? $shop_name[$item['id']] : ''; } print_r($arr);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 10
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 10
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 27
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 27
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 22
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
Branch analysis from position: 10
filename:       /in/ULCvX
function name:  (null)
number of ops:  32
compiled vars:  !0 = $arr, !1 = $arr2, !2 = $shop_name, !3 = $item, !4 = $key, !5 = $exist
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   17     1        ASSIGN                                                   !1, <array>
   50     2        ASSIGN                                                   !2, <array>
   51     3      > FE_RESET_R                                       $9      !1, ->10
          4    > > FE_FETCH_R                                               $9, !3, ->10
          5    >   FETCH_DIM_R                                      ~10     !3, 'id'
          6        FETCH_DIM_R                                      ~12     !3, 'shop_name'
          7        ASSIGN_DIM                                               !2, ~10
          8        OP_DATA                                                  ~12
          9      > JMP                                                      ->4
         10    >   FE_FREE                                                  $9
   53    11      > FE_RESET_R                                       $13     !0, ->27
         12    > > FE_FETCH_R                                       ~14     $13, !3, ->27
         13    >   ASSIGN                                                   !4, ~14
   54    14        FETCH_DIM_R                                      ~16     !3, 'id'
         15        ARRAY_KEY_EXISTS                                 ~17     ~16, !2
         16        ASSIGN                                                   !5, ~17
   55    17      > JMPZ                                                     !5, ->22
         18    >   FETCH_DIM_R                                      ~21     !3, 'id'
         19        FETCH_DIM_R                                      ~22     !2, ~21
         20        QM_ASSIGN                                        ~23     ~22
         21      > JMP                                                      ->23
         22    >   QM_ASSIGN                                        ~23     ''
         23    >   FETCH_DIM_W                                      $19     !0, !4
         24        ASSIGN_DIM                                               $19, 'shop_name'
         25        OP_DATA                                                  ~23
   53    26      > JMP                                                      ->12
         27    >   FE_FREE                                                  $13
   58    28        INIT_FCALL                                               'print_r'
         29        SEND_VAR                                                 !0
         30        DO_ICALL                                                 
         31      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.95 ms | 1396 KiB | 15 Q