3v4l.org

run code in 300+ PHP versions simultaneously
<?php $items = array( [ 'menu_id' => 10, 'current_price' => 150, 'num' => 10 ], [ 'menu_id' => 12, 'current_price' => 200, 'num' => 20 ], [ 'menu_id' => 10, 'current_price' => 150, 'num' => 30 ], ['menu_id' => 11, 'current_price' => 100, 'num' => 40 ], [ 'menu_id' => 11, 'current_price' => 100, 'num' => 50 ], ['menu_id' => 11, 'current_price' => 200, 'num' => 60 ], ['menu_id' => 13, 'current_price' => 300, 'num' => 70 ] ) ; $grouped = []; foreach($items as $v){ $index = $v['menu_id'].'-'.$v['current_price']; isset($grouped[$index]) ? ($grouped[$index]['num'] += $v['num']) : ($grouped[$index] = $v); } print_r($grouped);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 22
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 22
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 17
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/MYEYO
function name:  (null)
number of ops:  27
compiled vars:  !0 = $items, !1 = $grouped, !2 = $v, !3 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   11     1        ASSIGN                                                   !1, <array>
   12     2      > FE_RESET_R                                       $6      !0, ->22
          3    > > FE_FETCH_R                                               $6, !2, ->22
   13     4    >   FETCH_DIM_R                                      ~7      !2, 'menu_id'
          5        CONCAT                                           ~8      ~7, '-'
          6        FETCH_DIM_R                                      ~9      !2, 'current_price'
          7        CONCAT                                           ~10     ~8, ~9
          8        ASSIGN                                                   !3, ~10
   14     9        ISSET_ISEMPTY_DIM_OBJ                         0          !1, !3
         10      > JMPZ                                                     ~12, ->17
         11    >   FETCH_DIM_R                                      ~15     !2, 'num'
         12        FETCH_DIM_RW                                     $13     !1, !3
         13        ASSIGN_DIM_OP                +=               1  ~14     $13, 'num'
         14        OP_DATA                                                  ~15
         15        QM_ASSIGN                                        ~16     ~14
         16      > JMP                                                      ->20
         17    >   ASSIGN_DIM                                       ~17     !1, !3
         18        OP_DATA                                                  !2
         19        QM_ASSIGN                                        ~16     ~17
         20    >   FREE                                                     ~16
   12    21      > JMP                                                      ->3
         22    >   FE_FREE                                                  $6
   16    23        INIT_FCALL                                               'print_r'
         24        SEND_VAR                                                 !1
         25        DO_ICALL                                                 
         26      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.87 ms | 1407 KiB | 15 Q