3v4l.org

run code in 300+ 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                                  '%00%7Bclosure%7D%2Fin%2FEfdTM%3A35%240'
         12        BIND_LEXICAL                                             ~9, !2
         13        BIND_LEXICAL                                             ~9, !1
   38    14        SEND_VAL                                                 ~9
         15        SEND_VAR                                                 !0
         16        DO_ICALL                                         $10     
   35    17        ASSIGN                                                   !3, $10
   40    18        INIT_FCALL                                               'var_dump'
         19        SEND_VAR                                                 !3
         20        DO_ICALL                                                 
         21      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FEfdTM%3A35%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EfdTM
function name:  {closure}
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 function %00%7Bclosure%7D%2Fin%2FEfdTM%3A35%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
212.65 ms | 1396 KiB | 21 Q