3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Data $name = ['Mazda','Mazda','Lexus', 'Lexus']; $count = [1,1,1,1]; $gp =[54,35,23,46]; // declare result array $result = []; for($i = 0; $i < count($name); $i++) { $result[ $name[$i] ] = [ "C" => ($result[ $name[$i] ]['C'] ?? 0) + $count[$i], "GP" => ($result[ $name[$i] ]['GP'] ?? 0) + $gp[$i] ]; } print_r($result);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 6
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 6
Branch analysis from position: 29
Branch analysis from position: 6
filename:       /in/U3nQ0
function name:  (null)
number of ops:  33
compiled vars:  !0 = $name, !1 = $count, !2 = $gp, !3 = $result, !4 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, <array>
    5     1        ASSIGN                                                   !1, <array>
    6     2        ASSIGN                                                   !2, <array>
    9     3        ASSIGN                                                   !3, <array>
   11     4        ASSIGN                                                   !4, 0
          5      > JMP                                                      ->26
   12     6    >   FETCH_DIM_R                                      ~10     !0, !4
   13     7        FETCH_DIM_R                                      ~12     !0, !4
          8        FETCH_DIM_IS                                     ~13     !3, ~12
          9        FETCH_DIM_IS                                     ~14     ~13, 'C'
         10        COALESCE                                         ~15     ~14
         11        QM_ASSIGN                                        ~15     0
         12        FETCH_DIM_R                                      ~16     !1, !4
         13        ADD                                              ~17     ~15, ~16
         14        INIT_ARRAY                                       ~18     ~17, 'C'
   14    15        FETCH_DIM_R                                      ~19     !0, !4
         16        FETCH_DIM_IS                                     ~20     !3, ~19
         17        FETCH_DIM_IS                                     ~21     ~20, 'GP'
         18        COALESCE                                         ~22     ~21
         19        QM_ASSIGN                                        ~22     0
         20        FETCH_DIM_R                                      ~23     !2, !4
         21        ADD                                              ~24     ~22, ~23
         22        ADD_ARRAY_ELEMENT                                ~18     ~24, 'GP'
   12    23        ASSIGN_DIM                                               !3, ~10
   14    24        OP_DATA                                                  ~18
   11    25        PRE_INC                                                  !4
         26    >   COUNT                                            ~26     !0
         27        IS_SMALLER                                               !4, ~26
         28      > JMPNZ                                                    ~27, ->6
   17    29    >   INIT_FCALL                                               'print_r'
         30        SEND_VAR                                                 !3
         31        DO_ICALL                                                 
         32      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.2 ms | 1401 KiB | 15 Q