3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array_list= array("Jan 2016"=>2, "Feb 2016"=>4, "Mar 2016"=>2,"Apr 2016"=>0, "Jan 2017"=>9,"Feb 2017"=>2,"Mar 2017"=>5,"Jan 2018"=>4,"Feb 2018"=>6); $start = microtime(1); $array = array(); foreach($array_list as $key => $value): $MonthYear_label = explode(" ",$key); $year_label = $MonthYear_label[1]; $month_label = $MonthYear_label[0]; $curr_year = $year_label; $array[$curr_year]['count'] = $array[$curr_year]['count'] + $value; endforeach; echo (microtime(1)-$start)*1000 . "\n"; $start = microtime(1); foreach(array_keys($array_list) as $key){ $years[] = explode(" ", $key)[1]; } foreach(array_unique($years) as $year){ $res[$year] = array_sum(array_intersect_key(array_values($array_list), array_intersect($years, [$year]))); } echo (microtime(1)-$start)*1000 . "\n";
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 26
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 26
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 26
2 jumps found. (Code = 77) Position 1 = 42, Position 2 = 51
Branch analysis from position: 42
2 jumps found. (Code = 78) Position 1 = 43, Position 2 = 51
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
Branch analysis from position: 51
2 jumps found. (Code = 77) Position 1 = 56, Position 2 = 75
Branch analysis from position: 56
2 jumps found. (Code = 78) Position 1 = 57, Position 2 = 75
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 56
Branch analysis from position: 56
Branch analysis from position: 75
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 75
Branch analysis from position: 51
Branch analysis from position: 26
filename:       /in/OgT0a
function name:  (null)
number of ops:  84
compiled vars:  !0 = $array_list, !1 = $start, !2 = $array, !3 = $value, !4 = $key, !5 = $MonthYear_label, !6 = $year_label, !7 = $month_label, !8 = $curr_year, !9 = $years, !10 = $year, !11 = $res
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        INIT_FCALL                                               'microtime'
          2        SEND_VAL                                                 1
          3        DO_ICALL                                         $13     
          4        ASSIGN                                                   !1, $13
    5     5        ASSIGN                                                   !2, <array>
    6     6      > FE_RESET_R                                       $16     !0, ->26
          7    > > FE_FETCH_R                                       ~17     $16, !3, ->26
          8    >   ASSIGN                                                   !4, ~17
    7     9        INIT_FCALL                                               'explode'
         10        SEND_VAL                                                 '+'
         11        SEND_VAR                                                 !4
         12        DO_ICALL                                         $19     
         13        ASSIGN                                                   !5, $19
    8    14        FETCH_DIM_R                                      ~21     !5, 1
         15        ASSIGN                                                   !6, ~21
    9    16        FETCH_DIM_R                                      ~23     !5, 0
         17        ASSIGN                                                   !7, ~23
   10    18        ASSIGN                                                   !8, !6
   11    19        FETCH_DIM_R                                      ~28     !2, !8
         20        FETCH_DIM_R                                      ~29     ~28, 'count'
         21        ADD                                              ~30     ~29, !3
         22        FETCH_DIM_W                                      $26     !2, !8
         23        ASSIGN_DIM                                               $26, 'count'
         24        OP_DATA                                                  ~30
    6    25      > JMP                                                      ->7
         26    >   FE_FREE                                                  $16
   13    27        INIT_FCALL                                               'microtime'
         28        SEND_VAL                                                 1
         29        DO_ICALL                                         $31     
         30        SUB                                              ~32     $31, !1
         31        MUL                                              ~33     ~32, 1000
         32        CONCAT                                           ~34     ~33, '%0A'
         33        ECHO                                                     ~34
   15    34        INIT_FCALL                                               'microtime'
         35        SEND_VAL                                                 1
         36        DO_ICALL                                         $35     
         37        ASSIGN                                                   !1, $35
   16    38        INIT_FCALL                                               'array_keys'
         39        SEND_VAR                                                 !0
         40        DO_ICALL                                         $37     
         41      > FE_RESET_R                                       $38     $37, ->51
         42    > > FE_FETCH_R                                               $38, !4, ->51
   17    43    >   INIT_FCALL                                               'explode'
         44        SEND_VAL                                                 '+'
         45        SEND_VAR                                                 !4
         46        DO_ICALL                                         $40     
         47        FETCH_DIM_R                                      ~41     $40, 1
         48        ASSIGN_DIM                                               !9
         49        OP_DATA                                                  ~41
   16    50      > JMP                                                      ->42
         51    >   FE_FREE                                                  $38
   20    52        INIT_FCALL                                               'array_unique'
         53        SEND_VAR                                                 !9
         54        DO_ICALL                                         $42     
         55      > FE_RESET_R                                       $43     $42, ->75
         56    > > FE_FETCH_R                                               $43, !10, ->75
   21    57    >   INIT_FCALL                                               'array_sum'
         58        INIT_FCALL                                               'array_intersect_key'
         59        INIT_FCALL                                               'array_values'
         60        SEND_VAR                                                 !0
         61        DO_ICALL                                         $45     
         62        SEND_VAR                                                 $45
         63        INIT_FCALL                                               'array_intersect'
         64        SEND_VAR                                                 !9
         65        INIT_ARRAY                                       ~46     !10
         66        SEND_VAL                                                 ~46
         67        DO_ICALL                                         $47     
         68        SEND_VAR                                                 $47
         69        DO_ICALL                                         $48     
         70        SEND_VAR                                                 $48
         71        DO_ICALL                                         $49     
         72        ASSIGN_DIM                                               !11, !10
         73        OP_DATA                                                  $49
   20    74      > JMP                                                      ->56
         75    >   FE_FREE                                                  $43
   23    76        INIT_FCALL                                               'microtime'
         77        SEND_VAL                                                 1
         78        DO_ICALL                                         $50     
         79        SUB                                              ~51     $50, !1
         80        MUL                                              ~52     ~51, 1000
         81        CONCAT                                           ~53     ~52, '%0A'
         82        ECHO                                                     ~53
         83      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.46 ms | 1014 KiB | 21 Q