3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ ['id' => 1, 'product_id' => 4, 'product_number' => 10, 'moving_type' => 1], ['id' => 1, 'product_id' => 5, 'product_number' => 10, 'moving_type' => 1], ['id' => 1, 'product_id' => 5, 'product_number' => 2, 'moving_type' => 2] ]; foreach ($array as $row) { if (!isset($result[$row['product_id']])) { $result[$row['product_id']] = array_slice($row, 0, 3, true); } else { $result[$row['product_id']]['product_number'] += ($row['moving_type'] == 1 ? 1 : -1) * $row['product_number']; } } var_export(array_values($result));
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 30
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 30
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 17
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 23
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/BYfZf
function name:  (null)
number of ops:  38
compiled vars:  !0 = $array, !1 = $row, !2 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    8     1      > FE_RESET_R                                       $4      !0, ->30
          2    > > FE_FETCH_R                                               $4, !1, ->30
    9     3    >   FETCH_DIM_R                                      ~5      !1, 'product_id'
          4        ISSET_ISEMPTY_DIM_OBJ                         0  ~6      !2, ~5
          5        BOOL_NOT                                         ~7      ~6
          6      > JMPZ                                                     ~7, ->17
   10     7    >   FETCH_DIM_R                                      ~8      !1, 'product_id'
          8        INIT_FCALL                                               'array_slice'
          9        SEND_VAR                                                 !1
         10        SEND_VAL                                                 0
         11        SEND_VAL                                                 3
         12        SEND_VAL                                                 <true>
         13        DO_ICALL                                         $10     
         14        ASSIGN_DIM                                               !2, ~8
         15        OP_DATA                                                  $10
    9    16      > JMP                                                      ->29
   12    17    >   FETCH_DIM_R                                      ~11     !1, 'product_id'
         18        FETCH_DIM_R                                      ~14     !1, 'moving_type'
         19        IS_EQUAL                                                 ~14, 1
         20      > JMPZ                                                     ~15, ->23
         21    >   QM_ASSIGN                                        ~16     1
         22      > JMP                                                      ->24
         23    >   QM_ASSIGN                                        ~16     -1
         24    >   FETCH_DIM_R                                      ~17     !1, 'product_number'
         25        MUL                                              ~18     ~16, ~17
         26        FETCH_DIM_RW                                     $12     !2, ~11
         27        ASSIGN_DIM_OP                +=               1          $12, 'product_number'
         28        OP_DATA                                                  ~18
    8    29    > > JMP                                                      ->2
         30    >   FE_FREE                                                  $4
   16    31        INIT_FCALL                                               'var_export'
         32        INIT_FCALL                                               'array_values'
         33        SEND_VAR                                                 !2
         34        DO_ICALL                                         $19     
         35        SEND_VAR                                                 $19
         36        DO_ICALL                                                 
         37      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
270.64 ms | 1017 KiB | 16 Q