3v4l.org

run code in 300+ PHP versions simultaneously
<?php date_default_timezone_set('UTC'); $dates = 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 20:00:00', '2014-01-25 20:00:00', '2014-01-26 20:00:00', '2014-01-31 20:00:00', '2014-02-01 20:00:00' ); function getDateRanges($dates) { $tsArr = array_map('strtotime', $dates); $ranges = array(); for ($i=0, $len = count($tsArr); $i < $len; $i++) { $rstart = $tsArr[$i]; $rend = $rstart; // determine the end of the range while (isset($tsArr[$i+1]) && ($tsArr[$i+1]-$tsArr[$i]) / (60*60) <= 24) { $rend = $tsArr[++$i]; } // create DateTime objects to work with dates $startDate = new DateTime('@'.$rstart); $endDate = new DateTime('@'.$rend); // get date start and last day of month $start = $startDate->format('j'); $lastDay = $startDate->format('t'); // if last day of month, append month name if ($start == $lastDay) $start = $startDate->format('jS M'); else $start = $startDate->format('jS'); // end date $end = $endDate->format('jS M ga'); $ranges[] = $start.'-'.$end; } return $ranges; } $arr = getDateRanges($dates); echo implode(', ', $arr);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cVrfe
function name:  (null)
number of ops:  14
compiled vars:  !0 = $dates, !1 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'date_default_timezone_set'
          1        SEND_VAL                                                 'UTC'
          2        DO_ICALL                                                 
    6     3        ASSIGN                                                   !0, <array>
   58     4        INIT_FCALL                                               'getdateranges'
          5        SEND_VAR                                                 !0
          6        DO_FCALL                                      0  $4      
          7        ASSIGN                                                   !1, $4
   59     8        INIT_FCALL                                               'implode'
          9        SEND_VAL                                                 '%2C+'
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $6      
         12        ECHO                                                     $6
         13      > RETURN                                                   1

Function getdateranges:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 67
Branch analysis from position: 67
2 jumps found. (Code = 44) Position 1 = 69, Position 2 = 11
Branch analysis from position: 69
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 46) Position 1 = 21, Position 2 = 28
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 15
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 54
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 58
Branch analysis from position: 58
2 jumps found. (Code = 44) Position 1 = 69, Position 2 = 11
Branch analysis from position: 69
Branch analysis from position: 11
Branch analysis from position: 54
2 jumps found. (Code = 44) Position 1 = 69, Position 2 = 11
Branch analysis from position: 69
Branch analysis from position: 11
Branch analysis from position: 15
2 jumps found. (Code = 46) Position 1 = 21, Position 2 = 28
Branch analysis from position: 21
Branch analysis from position: 28
Branch analysis from position: 28
filename:       /in/cVrfe
function name:  getDateRanges
number of ops:  71
compiled vars:  !0 = $dates, !1 = $tsArr, !2 = $ranges, !3 = $i, !4 = $len, !5 = $rstart, !6 = $rend, !7 = $startDate, !8 = $endDate, !9 = $start, !10 = $lastDay, !11 = $end
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   20     1        INIT_FCALL                                               'array_map'
          2        SEND_VAL                                                 'strtotime'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $12     
          5        ASSIGN                                                   !1, $12
   21     6        ASSIGN                                                   !2, <array>
   23     7        ASSIGN                                                   !3, 0
          8        COUNT                                            ~16     !1
          9        ASSIGN                                                   !4, ~16
         10      > JMP                                                      ->67
   25    11    >   FETCH_DIM_R                                      ~18     !1, !3
         12        ASSIGN                                                   !5, ~18
   26    13        ASSIGN                                                   !6, !5
   29    14      > JMP                                                      ->18
   30    15    >   PRE_INC                                          ~21     !3
         16        FETCH_DIM_R                                      ~22     !1, ~21
         17        ASSIGN                                                   !6, ~22
   29    18    >   ADD                                              ~24     !3, 1
         19        ISSET_ISEMPTY_DIM_OBJ                         0  ~25     !1, ~24
         20      > JMPZ_EX                                          ~25     ~25, ->28
         21    >   ADD                                              ~26     !3, 1
         22        FETCH_DIM_R                                      ~27     !1, ~26
         23        FETCH_DIM_R                                      ~28     !1, !3
         24        SUB                                              ~29     ~27, ~28
         25        DIV                                              ~30     ~29, 3600
         26        IS_SMALLER_OR_EQUAL                              ~31     ~30, 24
         27        BOOL                                             ~25     ~31
         28    > > JMPNZ                                                    ~25, ->15
   34    29    >   NEW                                              $32     'DateTime'
         30        CONCAT                                           ~33     '%40', !5
         31        SEND_VAL_EX                                              ~33
         32        DO_FCALL                                      0          
         33        ASSIGN                                                   !7, $32
   35    34        NEW                                              $36     'DateTime'
         35        CONCAT                                           ~37     '%40', !6
         36        SEND_VAL_EX                                              ~37
         37        DO_FCALL                                      0          
         38        ASSIGN                                                   !8, $36
   38    39        INIT_METHOD_CALL                                         !7, 'format'
         40        SEND_VAL_EX                                              'j'
         41        DO_FCALL                                      0  $40     
         42        ASSIGN                                                   !9, $40
   39    43        INIT_METHOD_CALL                                         !7, 'format'
         44        SEND_VAL_EX                                              't'
         45        DO_FCALL                                      0  $42     
         46        ASSIGN                                                   !10, $42
   42    47        IS_EQUAL                                                 !9, !10
         48      > JMPZ                                                     ~44, ->54
   43    49    >   INIT_METHOD_CALL                                         !7, 'format'
         50        SEND_VAL_EX                                              'jS+M'
         51        DO_FCALL                                      0  $45     
         52        ASSIGN                                                   !9, $45
         53      > JMP                                                      ->58
   45    54    >   INIT_METHOD_CALL                                         !7, 'format'
         55        SEND_VAL_EX                                              'jS'
         56        DO_FCALL                                      0  $47     
         57        ASSIGN                                                   !9, $47
   48    58    >   INIT_METHOD_CALL                                         !8, 'format'
         59        SEND_VAL_EX                                              'jS+M+ga'
         60        DO_FCALL                                      0  $49     
         61        ASSIGN                                                   !11, $49
   50    62        CONCAT                                           ~52     !9, '-'
         63        CONCAT                                           ~53     ~52, !11
         64        ASSIGN_DIM                                               !2
         65        OP_DATA                                                  ~53
   23    66        PRE_INC                                                  !3
         67    >   IS_SMALLER                                               !3, !4
         68      > JMPNZ                                                    ~55, ->11
   52    69    > > RETURN                                                   !2
   53    70*     > RETURN                                                   null

End of function getdateranges

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.4 ms | 1407 KiB | 20 Q