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 = []; foreach ($arr2 as $item) $keys[$item['id']] = $item['stock']; $newArr = array_map(function($item) use($keys){ $item['stock'] = $keys[$item['id']]; return $item; }, $arr1); var_dump($newArr);
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
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/7PFAA
function name:  (null)
number of ops:  22
compiled vars:  !0 = $arr1, !1 = $arr2, !2 = $keys, !3 = $item, !4 = $newArr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   19     1        ASSIGN                                                   !1, <array>
   34     2        ASSIGN                                                   !2, <array>
   35     3      > FE_RESET_R                                       $8      !1, ->10
          4    > > FE_FETCH_R                                               $8, !3, ->10
   36     5    >   FETCH_DIM_R                                      ~9      !3, 'id'
          6        FETCH_DIM_R                                      ~11     !3, 'stock'
          7        ASSIGN_DIM                                               !2, ~9
          8        OP_DATA                                                  ~11
   35     9      > JMP                                                      ->4
         10    >   FE_FREE                                                  $8
   38    11        INIT_FCALL                                               'array_map'
         12        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F7PFAA%3A38%240'
         13        BIND_LEXICAL                                             ~12, !2
   41    14        SEND_VAL                                                 ~12
         15        SEND_VAR                                                 !0
         16        DO_ICALL                                         $13     
   38    17        ASSIGN                                                   !4, $13
   43    18        INIT_FCALL                                               'var_dump'
         19        SEND_VAR                                                 !4
         20        DO_ICALL                                                 
         21      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2F7PFAA%3A38%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7PFAA
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $item, !1 = $keys
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   39     2        FETCH_DIM_R                                      ~3      !0, 'id'
          3        FETCH_DIM_R                                      ~4      !1, ~3
          4        ASSIGN_DIM                                               !0, 'stock'
          5        OP_DATA                                                  ~4
   40     6      > RETURN                                                   !0
   41     7*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F7PFAA%3A38%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
176.2 ms | 1396 KiB | 17 Q