3v4l.org

run code in 300+ PHP versions simultaneously
<?php $ar = [["count"=>6,"year"=>2019,"month"=>10,"name"=>"P","id"=>3,], ["count"=>2,"year"=>2019,"month"=>10,"name"=>"s.vimal","id"=>1,], ["count"=>4,"year"=>2019,"month"=>10,"name"=>"MR","id"=>2,], ["count"=>11,"year"=>2019,"month"=>11,"name"=>"s.vimal","id"=>1,], ["count"=>1,"year"=>2019,"month"=>12,"name"=>"MR","id"=>2,], ["count"=>4,"year"=>2019,"month"=>11,"name"=>"vimaltest","id"=>10,], ["count"=>1,"year"=>2019,"month"=>12,"name"=>"vimaltest","id"=>10,]]; $mon_ar = array_unique(array_column($ar,'month')); $year_ar = array_unique(array_column($ar,'year')); foreach($ar as $rec){ foreach($year_ar as $year){ foreach($mon_ar as $month){ if (!isset($result[$year.$month])) $result[$year.$month] = [ 'month' => $month, 'year' => $year]; if ($rec['year'] == $year && $rec['month'] <= $month) { if (!isset($result[$year.$month][$rec['name']])) $result[$year.$month][$rec['name']] = 0; $result[$year.$month][$rec['name']] += $rec['count']; } } } } sort($result); print_r($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 61
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 61
Branch analysis from position: 19
2 jumps found. (Code = 77) Position 1 = 20, Position 2 = 59
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 59
Branch analysis from position: 21
2 jumps found. (Code = 77) Position 1 = 22, Position 2 = 57
Branch analysis from position: 22
2 jumps found. (Code = 78) Position 1 = 23, Position 2 = 57
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 32
Branch analysis from position: 27
2 jumps found. (Code = 46) Position 1 = 35, Position 2 = 38
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 56
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 50
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 50
Branch analysis from position: 56
Branch analysis from position: 38
Branch analysis from position: 32
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 57
Branch analysis from position: 59
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 59
Branch analysis from position: 61
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 61
filename:       /in/Xf35f
function name:  (null)
number of ops:  69
compiled vars:  !0 = $ar, !1 = $mon_ar, !2 = $year_ar, !3 = $rec, !4 = $year, !5 = $month, !6 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   11     1        INIT_FCALL                                               'array_unique'
          2        INIT_FCALL                                               'array_column'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 'month'
          5        DO_ICALL                                         $8      
          6        SEND_VAR                                                 $8
          7        DO_ICALL                                         $9      
          8        ASSIGN                                                   !1, $9
   12     9        INIT_FCALL                                               'array_unique'
         10        INIT_FCALL                                               'array_column'
         11        SEND_VAR                                                 !0
         12        SEND_VAL                                                 'year'
         13        DO_ICALL                                         $11     
         14        SEND_VAR                                                 $11
         15        DO_ICALL                                         $12     
         16        ASSIGN                                                   !2, $12
   14    17      > FE_RESET_R                                       $14     !0, ->61
         18    > > FE_FETCH_R                                               $14, !3, ->61
   15    19    > > FE_RESET_R                                       $15     !2, ->59
         20    > > FE_FETCH_R                                               $15, !4, ->59
   16    21    > > FE_RESET_R                                       $16     !1, ->57
         22    > > FE_FETCH_R                                               $16, !5, ->57
   18    23    >   CONCAT                                           ~17     !4, !5
         24        ISSET_ISEMPTY_DIM_OBJ                         0  ~18     !6, ~17
         25        BOOL_NOT                                         ~19     ~18
         26      > JMPZ                                                     ~19, ->32
         27    >   CONCAT                                           ~20     !4, !5
         28        INIT_ARRAY                                       ~22     !5, 'month'
         29        ADD_ARRAY_ELEMENT                                ~22     !4, 'year'
         30        ASSIGN_DIM                                               !6, ~20
         31        OP_DATA                                                  ~22
   20    32    >   FETCH_DIM_R                                      ~23     !3, 'year'
         33        IS_EQUAL                                         ~24     !4, ~23
         34      > JMPZ_EX                                          ~24     ~24, ->38
         35    >   FETCH_DIM_R                                      ~25     !3, 'month'
         36        IS_SMALLER_OR_EQUAL                              ~26     ~25, !5
         37        BOOL                                             ~24     ~26
         38    > > JMPZ                                                     ~24, ->56
   21    39    >   CONCAT                                           ~27     !4, !5
         40        FETCH_DIM_R                                      ~29     !3, 'name'
         41        FETCH_DIM_IS                                     ~28     !6, ~27
         42        ISSET_ISEMPTY_DIM_OBJ                         0  ~30     ~28, ~29
         43        BOOL_NOT                                         ~31     ~30
         44      > JMPZ                                                     ~31, ->50
         45    >   CONCAT                                           ~32     !4, !5
         46        FETCH_DIM_R                                      ~34     !3, 'name'
         47        FETCH_DIM_W                                      $33     !6, ~32
         48        ASSIGN_DIM                                               $33, ~34
         49        OP_DATA                                                  0
   22    50    >   CONCAT                                           ~36     !4, !5
         51        FETCH_DIM_R                                      ~38     !3, 'name'
         52        FETCH_DIM_R                                      ~40     !3, 'count'
         53        FETCH_DIM_RW                                     $37     !6, ~36
         54        ASSIGN_DIM_OP                +=               1          $37, ~38
         55        OP_DATA                                                  ~40
   16    56    > > JMP                                                      ->22
         57    >   FE_FREE                                                  $16
   15    58      > JMP                                                      ->20
         59    >   FE_FREE                                                  $15
   14    60      > JMP                                                      ->18
         61    >   FE_FREE                                                  $14
   28    62        INIT_FCALL                                               'sort'
         63        SEND_REF                                                 !6
         64        DO_ICALL                                                 
   30    65        INIT_FCALL                                               'print_r'
         66        SEND_VAR                                                 !6
         67        DO_ICALL                                                 
         68      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.32 ms | 1013 KiB | 17 Q