3v4l.org

run code in 300+ PHP versions simultaneously
<?php $stocks = [ ['product_id'=>2, 'stocks'=>50], ['product_id'=>3, 'stocks'=>100], ['product_id'=>4, 'stocks'=>20], ['product_id'=>5, 'stocks'=>60] ]; $sales = [ ['product_id'=>4, 'quantity'=>3], ['product_id'=>5, 'quantity'=>30] ]; $keyed = array_column($sales, 'quantity', 'product_id'); var_export($keyed); echo "\n---\n"; foreach ($stocks as &$row) { // modify by reference if (isset($keyed[$row['product_id']])) { // search for product_id match $row['stocks'] -= $keyed[$row['product_id']]; // subtract } } var_export($stocks);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 13, Position 2 = 22
Branch analysis from position: 13
2 jumps found. (Code = 126) Position 1 = 14, Position 2 = 22
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 21
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 21
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/3YEK9
function name:  (null)
number of ops:  27
compiled vars:  !0 = $stocks, !1 = $sales, !2 = $keyed, !3 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    8     1        ASSIGN                                                   !1, <array>
   13     2        INIT_FCALL                                               'array_column'
          3        SEND_VAR                                                 !1
          4        SEND_VAL                                                 'quantity'
          5        SEND_VAL                                                 'product_id'
          6        DO_ICALL                                         $6      
          7        ASSIGN                                                   !2, $6
   14     8        INIT_FCALL                                               'var_export'
          9        SEND_VAR                                                 !2
         10        DO_ICALL                                                 
   15    11        ECHO                                                     '%0A---%0A'
   17    12      > FE_RESET_RW                                      $9      !0, ->22
         13    > > FE_FETCH_RW                                              $9, !3, ->22
   18    14    >   FETCH_DIM_R                                      ~10     !3, 'product_id'
         15        ISSET_ISEMPTY_DIM_OBJ                         0          !2, ~10
         16      > JMPZ                                                     ~11, ->21
   19    17    >   FETCH_DIM_R                                      ~13     !3, 'product_id'
         18        FETCH_DIM_R                                      ~14     !2, ~13
         19        ASSIGN_DIM_OP                -=               2          !3, 'stocks'
         20        OP_DATA                                                  ~14
   17    21    > > JMP                                                      ->13
         22    >   FE_FREE                                                  $9
   23    23        INIT_FCALL                                               'var_export'
         24        SEND_VAR                                                 !0
         25        DO_ICALL                                                 
         26      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.41 ms | 1002 KiB | 15 Q