3v4l.org

run code in 300+ PHP versions simultaneously
<?php $basket = [ [ 'name' => 'apple', 'qty' => 5, ], [ 'name' => 'apple', 'qty' => 4, ], [ 'name' => 'pear', 'qty' => 4, ] ]; // need a function that would convert this to $output = []; foreach ($basket as $item) { $key = $item['name']; if (!isset($output[$key])) $output[$key] = 0; $output[$key] += $item['qty']; } var_dump($output); //$output = [['name' => 'apple', 'qty' => 9], ['name' => 'pear', 'qty' => 4]];
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 15
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 15
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 11
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/2476p
function name:  (null)
number of ops:  20
compiled vars:  !0 = $basket, !1 = $output, !2 = $item, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   21     1        ASSIGN                                                   !1, <array>
   23     2      > FE_RESET_R                                       $6      !0, ->15
          3    > > FE_FETCH_R                                               $6, !2, ->15
   24     4    >   FETCH_DIM_R                                      ~7      !2, 'name'
          5        ASSIGN                                                   !3, ~7
   25     6        ISSET_ISEMPTY_DIM_OBJ                         0  ~9      !1, !3
          7        BOOL_NOT                                         ~10     ~9
          8      > JMPZ                                                     ~10, ->11
          9    >   ASSIGN_DIM                                               !1, !3
         10        OP_DATA                                                  0
   26    11    >   FETCH_DIM_R                                      ~13     !2, 'qty'
         12        ASSIGN_DIM_OP                +=               1          !1, !3
         13        OP_DATA                                                  ~13
   23    14      > JMP                                                      ->3
         15    >   FE_FREE                                                  $6
   29    16        INIT_FCALL                                               'var_dump'
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                                 
   30    19      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.72 ms | 1395 KiB | 15 Q