3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ [1 => 2], [1 => 2], [2 => 1], [3 => 1], ]; $result = []; foreach ($array as $row) { $k = key($row); if (!isset($ref[$k])) { $ref[$k] = 0; $result[][$k] =& $ref[$k]; } $ref[$k] += $row[$k]; } var_export($result);
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 = 18
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 18
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/F6rpM
function name:  (null)
number of ops:  27
compiled vars:  !0 = $array, !1 = $result, !2 = $row, !3 = $k, !4 = $ref
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   10     1        ASSIGN                                                   !1, <array>
   11     2      > FE_RESET_R                                       $7      !0, ->22
          3    > > FE_FETCH_R                                               $7, !2, ->22
   12     4    >   INIT_FCALL                                               'key'
          5        SEND_VAR                                                 !2
          6        DO_ICALL                                         $8      
          7        ASSIGN                                                   !3, $8
   13     8        ISSET_ISEMPTY_DIM_OBJ                         0  ~10     !4, !3
          9        BOOL_NOT                                         ~11     ~10
         10      > JMPZ                                                     ~11, ->18
   14    11    >   ASSIGN_DIM                                               !4, !3
         12        OP_DATA                                                  0
   15    13        FETCH_DIM_W                                      $15     !4, !3
         14        MAKE_REF                                         $16     $15
         15        FETCH_DIM_W                                      $13     !1
         16        FETCH_DIM_W                                      $14     $13, !3
         17        ASSIGN_REF                                               $14, $16
   17    18    >   FETCH_DIM_R                                      ~19     !2, !3
         19        ASSIGN_DIM_OP                +=               1          !4, !3
         20        OP_DATA                                                  ~19
   11    21      > JMP                                                      ->3
         22    >   FE_FREE                                                  $7
   19    23        INIT_FCALL                                               'var_export'
         24        SEND_VAR                                                 !1
         25        DO_ICALL                                                 
         26      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.41 ms | 1012 KiB | 15 Q