3v4l.org

run code in 300+ PHP versions simultaneously
<?php $dates = [ '2010-12-30', '2011-01-01', '2011-01-02', '2011-01-03', '2011-01-06', '2011-01-06', '2011-01-07', '2011-01-10', ]; function formatRange(object $start, ?object $end = null): string { $last = $end ?? $start; return sprintf( '%s%s', $start->format('l j M'), $last === $start ? '' : ' to ' . $last->format('l j M') ); } $result = []; foreach ($dates as $date) { $obj = new Datetime($date); if (isset($temp['start'])) { if ($obj->diff($temp['end'] ?? $temp['start'])->days > 1) { $result[] = formatRange(...$temp); $temp = ['start' => $obj]; } else { $temp['end'] = $obj; } } else { $temp['start'] = $obj; } } if (isset($temp)) { $result[] = formatRange(...$temp); } var_export($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 35
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 35
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 32
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 29
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 44
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
Branch analysis from position: 35
filename:       /in/XgAG9
function name:  (null)
number of ops:  48
compiled vars:  !0 = $dates, !1 = $result, !2 = $date, !3 = $obj, !4 = $temp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   26     1        ASSIGN                                                   !1, <array>
   27     2      > FE_RESET_R                                       $7      !0, ->35
          3    > > FE_FETCH_R                                               $7, !2, ->35
   28     4    >   NEW                                              $8      'Datetime'
          5        SEND_VAR_EX                                              !2
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !3, $8
   29     8        ISSET_ISEMPTY_DIM_OBJ                         0          !4, 'start'
          9      > JMPZ                                                     ~11, ->32
   30    10    >   INIT_METHOD_CALL                                         !3, 'diff'
         11        FETCH_DIM_IS                                     ~12     !4, 'end'
         12        COALESCE                                         ~13     ~12
         13        FETCH_DIM_R                                      ~14     !4, 'start'
         14        QM_ASSIGN                                        ~13     ~14
         15        SEND_VAL_EX                                              ~13
         16        DO_FCALL                                      0  $15     
         17        FETCH_OBJ_R                                      ~16     $15, 'days'
         18        IS_SMALLER                                               1, ~16
         19      > JMPZ                                                     ~17, ->29
   31    20    >   INIT_FCALL                                               'formatrange'
         21        SEND_UNPACK                                              !4
         22        CHECK_UNDEF_ARGS                                         
         23        DO_FCALL                                      1  $19     
         24        ASSIGN_DIM                                               !1
         25        OP_DATA                                                  $19
   32    26        INIT_ARRAY                                       ~20     !3, 'start'
         27        ASSIGN                                                   !4, ~20
   30    28      > JMP                                                      ->31
   34    29    >   ASSIGN_DIM                                               !4, 'end'
         30        OP_DATA                                                  !3
   29    31    > > JMP                                                      ->34
   37    32    >   ASSIGN_DIM                                               !4, 'start'
         33        OP_DATA                                                  !3
   27    34    > > JMP                                                      ->3
         35    >   FE_FREE                                                  $7
   40    36        ISSET_ISEMPTY_CV                                         !4
         37      > JMPZ                                                     ~24, ->44
   41    38    >   INIT_FCALL                                               'formatrange'
         39        SEND_UNPACK                                              !4
         40        CHECK_UNDEF_ARGS                                         
         41        DO_FCALL                                      1  $26     
         42        ASSIGN_DIM                                               !1
         43        OP_DATA                                                  $26
   43    44    >   INIT_FCALL                                               'var_export'
         45        SEND_VAR                                                 !1
         46        DO_ICALL                                                 
         47      > RETURN                                                   1

Function formatrange:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 15
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XgAG9
function name:  formatRange
number of ops:  26
compiled vars:  !0 = $start, !1 = $end, !2 = $last
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
   16     2        COALESCE                                         ~3      !1
          3        QM_ASSIGN                                        ~3      !0
          4        ASSIGN                                                   !2, ~3
   17     5        INIT_FCALL                                               'sprintf'
   18     6        SEND_VAL                                                 '%25s%25s'
   19     7        INIT_METHOD_CALL                                         !0, 'format'
          8        SEND_VAL_EX                                              'l+j+M'
          9        DO_FCALL                                      0  $5      
         10        SEND_VAR                                                 $5
   20    11        IS_IDENTICAL                                             !2, !0
         12      > JMPZ                                                     ~6, ->15
   21    13    >   QM_ASSIGN                                        ~7      ''
         14      > JMP                                                      ->20
   22    15    >   INIT_METHOD_CALL                                         !2, 'format'
         16        SEND_VAL_EX                                              'l+j+M'
         17        DO_FCALL                                      0  $8      
         18        CONCAT                                           ~9      '+to+', $8
         19        QM_ASSIGN                                        ~7      ~9
         20    >   SEND_VAL                                                 ~7
   17    21        DO_ICALL                                         $10     
   22    22        VERIFY_RETURN_TYPE                                       $10
         23      > RETURN                                                   $10
   24    24*       VERIFY_RETURN_TYPE                                       
         25*     > RETURN                                                   null

End of function formatrange

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.68 ms | 1022 KiB | 17 Q