3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = array( "2014-01-20 20:00:00", "2014-01-21 20:00:00", "2014-01-22 14:00:00", "2014-01-22 20:00:00", "2014-01-23 14:00:00", "2014-01-23 20:00:00", "2014-01-25 20:00:00", "2014-01-26 12:00:00", "2014-01-26 20:00:00", "2014-01-31 20:00:00", "2014-02-01 20:00:00" ); $timestamps = array_map("strtotime", $input); $calendar = array(); foreach ($timestamps as $value) { $format = date("d.m.H", $value); list($day, $month, $hour) = explode(".", $format); if (!array_key_exists($month, $calendar)) $calendar[ $month ] = array(); if (!array_key_exists($day, $calendar[ $month ])) $calendar[ $month ][ $day ] = array(); $calendar[ $month ][ $day ][] = $hour; } $ranges = array(); // use reference so removing objects will affect all loops foreach ($calendar as $month => &$dates) { foreach ($dates as $date => $hours) { foreach ($hours as $key=>$hour) { // start checking for groups $currentDate = $date+1; $range = array($date); while (isset($dates[$currentDate]) && ($newkey = array_search($hour, $dates[$currentDate])) !== FALSE) { $range[] = $currentDate; unset($dates[$currentDate][$newkey]); $currentDate++; } // group was found if (count($range) != 1) { $ranges[] = array('dates' => $range, 'hour' => $hour); unset($dates[$date][$key]); } } } } print_r($calendar); print_r($ranges);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 42
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 42
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 30
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 37
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 37
Branch analysis from position: 30
Branch analysis from position: 42
2 jumps found. (Code = 125) Position 1 = 45, Position 2 = 88
Branch analysis from position: 45
2 jumps found. (Code = 126) Position 1 = 46, Position 2 = 88
Branch analysis from position: 46
2 jumps found. (Code = 77) Position 1 = 48, Position 2 = 86
Branch analysis from position: 48
2 jumps found. (Code = 78) Position 1 = 49, Position 2 = 86
Branch analysis from position: 49
2 jumps found. (Code = 77) Position 1 = 51, Position 2 = 84
Branch analysis from position: 51
2 jumps found. (Code = 78) Position 1 = 52, Position 2 = 84
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 63
Branch analysis from position: 63
2 jumps found. (Code = 46) Position 1 = 65, Position 2 = 73
Branch analysis from position: 65
2 jumps found. (Code = 44) Position 1 = 74, Position 2 = 58
Branch analysis from position: 74
2 jumps found. (Code = 43) Position 1 = 77, Position 2 = 83
Branch analysis from position: 77
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
Branch analysis from position: 83
Branch analysis from position: 58
2 jumps found. (Code = 46) Position 1 = 65, Position 2 = 73
Branch analysis from position: 65
Branch analysis from position: 73
Branch analysis from position: 73
Branch analysis from position: 84
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
Branch analysis from position: 84
Branch analysis from position: 86
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
Branch analysis from position: 86
Branch analysis from position: 88
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 88
Branch analysis from position: 42
filename:       /in/VH43p
function name:  (null)
number of ops:  96
compiled vars:  !0 = $input, !1 = $timestamps, !2 = $calendar, !3 = $value, !4 = $format, !5 = $day, !6 = $month, !7 = $hour, !8 = $ranges, !9 = $dates, !10 = $hours, !11 = $date, !12 = $key, !13 = $currentDate, !14 = $range, !15 = $newkey
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   17     1        INIT_FCALL                                               'array_map'
          2        SEND_VAL                                                 'strtotime'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $17     
          5        ASSIGN                                                   !1, $17
   19     6        ASSIGN                                                   !2, <array>
   20     7      > FE_RESET_R                                       $20     !1, ->42
          8    > > FE_FETCH_R                                               $20, !3, ->42
   21     9    >   INIT_FCALL                                               'date'
         10        SEND_VAL                                                 'd.m.H'
         11        SEND_VAR                                                 !3
         12        DO_ICALL                                         $21     
         13        ASSIGN                                                   !4, $21
   22    14        INIT_FCALL                                               'explode'
         15        SEND_VAL                                                 '.'
         16        SEND_VAR                                                 !4
         17        DO_ICALL                                         $23     
         18        FETCH_LIST_R                                     $24     $23, 0
         19        ASSIGN                                                   !5, $24
         20        FETCH_LIST_R                                     $26     $23, 1
         21        ASSIGN                                                   !6, $26
         22        FETCH_LIST_R                                     $28     $23, 2
         23        ASSIGN                                                   !7, $28
         24        FREE                                                     $23
   24    25        ARRAY_KEY_EXISTS                                 ~30     !6, !2
         26        BOOL_NOT                                         ~31     ~30
         27      > JMPZ                                                     ~31, ->30
   25    28    >   ASSIGN_DIM                                               !2, !6
         29        OP_DATA                                                  <array>
   27    30    >   FETCH_DIM_R                                      ~33     !2, !6
         31        ARRAY_KEY_EXISTS                                 ~34     !5, ~33
         32        BOOL_NOT                                         ~35     ~34
         33      > JMPZ                                                     ~35, ->37
   28    34    >   FETCH_DIM_W                                      $36     !2, !6
         35        ASSIGN_DIM                                               $36, !5
         36        OP_DATA                                                  <array>
   30    37    >   FETCH_DIM_W                                      $38     !2, !6
         38        FETCH_DIM_W                                      $39     $38, !5
         39        ASSIGN_DIM                                               $39
         40        OP_DATA                                                  !7
   20    41      > JMP                                                      ->8
         42    >   FE_FREE                                                  $20
   33    43        ASSIGN                                                   !8, <array>
   35    44      > FE_RESET_RW                                      $42     !2, ->88
         45    > > FE_FETCH_RW                                      ~43     $42, !9, ->88
         46    >   ASSIGN                                                   !6, ~43
   36    47      > FE_RESET_R                                       $45     !9, ->86
         48    > > FE_FETCH_R                                       ~46     $45, !10, ->86
         49    >   ASSIGN                                                   !11, ~46
   37    50      > FE_RESET_R                                       $48     !10, ->84
         51    > > FE_FETCH_R                                       ~49     $48, !7, ->84
         52    >   ASSIGN                                                   !12, ~49
   40    53        ADD                                              ~51     !11, 1
         54        ASSIGN                                                   !13, ~51
   41    55        INIT_ARRAY                                       ~53     !11
         56        ASSIGN                                                   !14, ~53
   42    57      > JMP                                                      ->63
   43    58    >   ASSIGN_DIM                                               !14
         59        OP_DATA                                                  !13
   44    60        FETCH_DIM_UNSET                                  $56     !9, !13
         61        UNSET_DIM                                                $56, !15
   45    62        PRE_INC                                                  !13
   42    63    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~58     !9, !13
         64      > JMPZ_EX                                          ~58     ~58, ->73
         65    >   INIT_FCALL                                               'array_search'
         66        SEND_VAR                                                 !7
         67        FETCH_DIM_R                                      ~59     !9, !13
         68        SEND_VAL                                                 ~59
         69        DO_ICALL                                         $60     
         70        ASSIGN                                           ~61     !15, $60
         71        TYPE_CHECK                                  1018  ~62     ~61
         72        BOOL                                             ~58     ~62
         73    > > JMPNZ                                                    ~58, ->58
   49    74    >   COUNT                                            ~63     !14
         75        IS_NOT_EQUAL                                             ~63, 1
         76      > JMPZ                                                     ~64, ->83
   50    77    >   INIT_ARRAY                                       ~66     !14, 'dates'
         78        ADD_ARRAY_ELEMENT                                ~66     !7, 'hour'
         79        ASSIGN_DIM                                               !8
         80        OP_DATA                                                  ~66
   51    81        FETCH_DIM_UNSET                                  $67     !9, !11
         82        UNSET_DIM                                                $67, !12
   37    83    > > JMP                                                      ->51
         84    >   FE_FREE                                                  $48
   36    85      > JMP                                                      ->48
         86    >   FE_FREE                                                  $45
   35    87      > JMP                                                      ->45
         88    >   FE_FREE                                                  $42
   57    89        INIT_FCALL                                               'print_r'
         90        SEND_VAR                                                 !2
         91        DO_ICALL                                                 
   58    92        INIT_FCALL                                               'print_r'
         93        SEND_VAR                                                 !8
         94        DO_ICALL                                                 
         95      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
168.97 ms | 1404 KiB | 23 Q