3v4l.org

run code in 500+ PHP versions simultaneously
<?php $sales = [ ["id" => 13, "name" => "Rahul", "sale_qty" => 2, "sale_weight" => 38.00], ["id" => 14, "name" => "shravandhika", "sale_qty" => 1, "sale_weight" => 12.00], ["id" => 3, "name" => "veena", "sale_qty" => 1, "sale_weight" => 19.00] ]; $returns = [ ["id" => 13, "name" => "Rahul", "sale_qty" => 1, "sale_weight" => 8.00], ["id" => 7, "name" => "sree", "sale_qty" => 1, "sale_weight" => 22.00] ]; $result = []; $items = array_merge($sales, $returns); foreach($items as $item) { $saleId = $item['id']; if (array_key_exists($saleId, $result)) { $result[$saleId]['sale_qty'] -= $item['sale_qty']; $result[$saleId]['sale_weight'] -= $item['sale_weight']; } else { $result[$saleId] = $item; } } print_r($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 26
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 26
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 23
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/LuSRV
function name:  (null)
number of ops:  31
compiled vars:  !0 = $sales, !1 = $returns, !2 = $result, !3 = $items, !4 = $item, !5 = $saleId
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
    9     1        ASSIGN                                                       !1, <array>
   14     2        ASSIGN                                                       !2, <array>
   15     3        INIT_FCALL                                                   'array_merge'
          4        SEND_VAR                                                     !0
          5        SEND_VAR                                                     !1
          6        DO_ICALL                                             $9      
          7        ASSIGN                                                       !3, $9
   17     8      > FE_RESET_R                                           $11     !3, ->26
          9    > > FE_FETCH_R                                                   $11, !4, ->26
   18    10    >   FETCH_DIM_R                                          ~12     !4, 'id'
         11        ASSIGN                                                       !5, ~12
   19    12        ARRAY_KEY_EXISTS                                             !5, !2
         13      > JMPZ                                                         ~14, ->23
   20    14    >   FETCH_DIM_R                                          ~17     !4, 'sale_qty'
         15        FETCH_DIM_RW                                         $15     !2, !5
         16        ASSIGN_DIM_OP                    -=               2          $15, 'sale_qty'
         17        OP_DATA                                                      ~17
   21    18        FETCH_DIM_R                                          ~20     !4, 'sale_weight'
         19        FETCH_DIM_RW                                         $18     !2, !5
         20        ASSIGN_DIM_OP                    -=               2          $18, 'sale_weight'
         21        OP_DATA                                                      ~20
   19    22      > JMP                                                          ->25
   23    23    >   ASSIGN_DIM                                                   !2, !5
         24        OP_DATA                                                      !4
   17    25    > > JMP                                                          ->9
         26    >   FE_FREE                                                      $11
   27    27        INIT_FCALL                                                   'print_r'
         28        SEND_VAR                                                     !2
         29        DO_ICALL                                                     
         30      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
215.05 ms | 1986 KiB | 15 Q