3v4l.org

run code in 500+ 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] ]; foreach ($stocks as &$row) { // modify by reference foreach ($sales as $k => $row2) { // search for product_id match if ($row['product_id'] == $row2['product_id']) { $row['stocks'] -= $row2['quantity']; // subtract unset($sales[$k]); // eliminate match from lookup array break; // assuming $sales['product_id'] values are unique } } } var_export($stocks);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 3, Position 2 = 19
Branch analysis from position: 3
2 jumps found. (Code = 126) Position 1 = 4, Position 2 = 19
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 17
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 17
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 16
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 17
Branch analysis from position: 17
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/D2YK6
function name:  (null)
number of ops:  24
compiled vars:  !0 = $stocks, !1 = $sales, !2 = $row, !3 = $row2, !4 = $k
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, <array>
    8     1        ASSIGN                                                       !1, <array>
   13     2      > FE_RESET_RW                                          $7      !0, ->19
          3    > > FE_FETCH_RW                                                  $7, !2, ->19
   14     4    > > FE_RESET_R                                           $8      !1, ->17
          5    > > FE_FETCH_R                                           ~9      $8, !3, ->17
          6    >   ASSIGN                                                       !4, ~9
   15     7        FETCH_DIM_R                                          ~11     !2, 'product_id'
          8        FETCH_DIM_R                                          ~12     !3, 'product_id'
          9        IS_EQUAL                                                     ~11, ~12
         10      > JMPZ                                                         ~13, ->16
   16    11    >   FETCH_DIM_R                                          ~15     !3, 'quantity'
         12        ASSIGN_DIM_OP                    -=               2          !2, 'stocks'
         13        OP_DATA                                                      ~15
   17    14        UNSET_DIM                                                    !1, !4
   18    15      > JMP                                                          ->17
   14    16    > > JMP                                                          ->5
         17    >   FE_FREE                                                      $8
   13    18      > JMP                                                          ->3
         19    >   FE_FREE                                                      $7
   23    20        INIT_FCALL                                                   'var_export'
         21        SEND_VAR                                                     !0
         22        DO_ICALL                                                     
         23      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
207.04 ms | 2675 KiB | 14 Q