3v4l.org

run code in 300+ PHP versions simultaneously
<?php $file = [ [0, 'a', 1, 2], [0, 'a', 1, 2], [0, 'b', 1, 2], ]; $fieldNames = [ 'id', 'location', 'blankets', 'sleepingbags' ]; $sumBlankets = []; foreach ($file as $i => $line) { $row = array_combine($fieldNames, $line); $k = $row['location']; // important if (!array_key_exists($k, $sumBlankets)) { $sumBlankets[$k] = ['blankets'=>0, 'sleepingbags'=>0]; } $sumBlankets[$k]['blankets'] += $row['blankets']; $sumBlankets[$k]['sleepingbags'] += $row['sleepingbags']; } var_export( $sumBlankets );
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 27
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 27
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 18
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
filename:       /in/hugBj
function name:  (null)
number of ops:  32
compiled vars:  !0 = $file, !1 = $fieldNames, !2 = $sumBlankets, !3 = $line, !4 = $i, !5 = $row, !6 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    8     1        ASSIGN                                                   !1, <array>
   15     2        ASSIGN                                                   !2, <array>
   17     3      > FE_RESET_R                                       $10     !0, ->27
          4    > > FE_FETCH_R                                       ~11     $10, !3, ->27
          5    >   ASSIGN                                                   !4, ~11
   18     6        INIT_FCALL                                               'array_combine'
          7        SEND_VAR                                                 !1
          8        SEND_VAR                                                 !3
          9        DO_ICALL                                         $13     
         10        ASSIGN                                                   !5, $13
   20    11        FETCH_DIM_R                                      ~15     !5, 'location'
         12        ASSIGN                                                   !6, ~15
   22    13        ARRAY_KEY_EXISTS                                 ~17     !6, !2
         14        BOOL_NOT                                         ~18     ~17
         15      > JMPZ                                                     ~18, ->18
   23    16    >   ASSIGN_DIM                                               !2, !6
         17        OP_DATA                                                  <array>
   26    18    >   FETCH_DIM_R                                      ~22     !5, 'blankets'
         19        FETCH_DIM_RW                                     $20     !2, !6
         20        ASSIGN_DIM_OP                +=               1          $20, 'blankets'
         21        OP_DATA                                                  ~22
   27    22        FETCH_DIM_R                                      ~25     !5, 'sleepingbags'
         23        FETCH_DIM_RW                                     $23     !2, !6
         24        ASSIGN_DIM_OP                +=               1          $23, 'sleepingbags'
         25        OP_DATA                                                  ~25
   17    26      > JMP                                                      ->4
         27    >   FE_FREE                                                  $10
   31    28        INIT_FCALL                                               'var_export'
         29        SEND_VAR                                                 !2
         30        DO_ICALL                                                 
         31      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.47 ms | 1400 KiB | 17 Q