3v4l.org

run code in 500+ PHP versions simultaneously
<?php $arr1 = [ [ "id"=>"3", "weight"=>"20", "percentage"=>"80", ], [ "id"=>"1", "weight"=>"50", "percentage"=>"80", ], [ "id"=>"2", "weight"=>"40", "percentage"=>"80", ] ]; $arr2 = [ [ "id"=>"1", "stock"=>"9539.00" ], [ "id"=>"2", "stock"=>"9468.00" ], [ "id"=>"3", "stock"=>"9295.00" ] ]; $keys = array_flip(array_column($arr2, 'id')); $newArr = array_map(function($item) use($keys, $arr2){ $item['stock'] = $arr2[$keys[$item['id']]]['stock']; return $item; }, $arr1); var_dump($newArr);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EfdTM
function name:  (null)
number of ops:  22
compiled vars:  !0 = $arr1, !1 = $arr2, !2 = $keys, !3 = $newArr
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, <array>
   19     1        ASSIGN                                                       !1, <array>
   34     2        INIT_FCALL                                                   'array_flip'
          3        INIT_FCALL                                                   'array_column'
          4        SEND_VAR                                                     !1
          5        SEND_VAL                                                     'id'
          6        DO_ICALL                                             $6      
          7        SEND_VAR                                                     $6
          8        DO_ICALL                                             $7      
          9        ASSIGN                                                       !2, $7
   35    10        INIT_FCALL                                                   'array_map'
         11        DECLARE_LAMBDA_FUNCTION                              ~9      [0]
         12        BIND_LEXICAL                                                 ~9, !2
         13        BIND_LEXICAL                                                 ~9, !1
   38    14        SEND_VAL                                                     ~9
         15        SEND_VAR                                                     !0
   35    16        DO_ICALL                                             $10     
         17        ASSIGN                                                       !3, $10
   40    18        INIT_FCALL                                                   'var_dump'
         19        SEND_VAR                                                     !3
         20        DO_ICALL                                                     
         21      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EfdTM
function name:  {closure:/in/EfdTM:35}
number of ops:  11
compiled vars:  !0 = $item, !1 = $keys, !2 = $arr2
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   35     0  E >   RECV                                                 !0      
          1        BIND_STATIC                                                  !1
          2        BIND_STATIC                                                  !2
   36     3        FETCH_DIM_R                                          ~4      !0, 'id'
          4        FETCH_DIM_R                                          ~5      !1, ~4
          5        FETCH_DIM_R                                          ~6      !2, ~5
          6        FETCH_DIM_R                                          ~7      ~6, 'stock'
          7        ASSIGN_DIM                                                   !0, 'stock'
          8        OP_DATA                                                      ~7
   37     9      > RETURN                                                       !0
   38    10*     > RETURN                                                       null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
172.09 ms | 3559 KiB | 17 Q