3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = ["01/06/18", "02/06/18", "03/06/18", "11/06/18","12/06/18", "13/06/18", "14/06/18", "15/06/18","16/06/18", "20/06/18"]; $i =-1; $prev =0; $format = "d/m/y"; Foreach($arr as $val){ $dt = date_create_from_format ($format , $val); $unix = date_timestamp_get($dt); If($unix -$prev > 86400){ $i++; } $res[$i][] = $unix; $prev = $unix; } Foreach($res as $period){ If(count($period) >1){ $periods[] = date($format, min($period)) . " - " . date($format, max($period)); }Else{ $periods[] = date($format, min($period)); } } Var_dump($periods);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 24
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 24
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 19
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 19
Branch analysis from position: 24
2 jumps found. (Code = 77) Position 1 = 26, Position 2 = 59
Branch analysis from position: 26
2 jumps found. (Code = 78) Position 1 = 27, Position 2 = 59
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 49
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 58
Branch analysis from position: 58
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 59
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 59
Branch analysis from position: 24
filename:       /in/gHDC0
function name:  (null)
number of ops:  64
compiled vars:  !0 = $arr, !1 = $i, !2 = $prev, !3 = $format, !4 = $val, !5 = $dt, !6 = $unix, !7 = $res, !8 = $period, !9 = $periods
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    7     1        ASSIGN                                                   !1, -1
    8     2        ASSIGN                                                   !2, 0
    9     3        ASSIGN                                                   !3, 'd%2Fm%2Fy'
   11     4      > FE_RESET_R                                       $14     !0, ->24
          5    > > FE_FETCH_R                                               $14, !4, ->24
   12     6    >   INIT_FCALL                                               'date_create_from_format'
          7        SEND_VAR                                                 !3
          8        SEND_VAR                                                 !4
          9        DO_ICALL                                         $15     
         10        ASSIGN                                                   !5, $15
   13    11        INIT_FCALL                                               'date_timestamp_get'
         12        SEND_VAR                                                 !5
         13        DO_ICALL                                         $17     
         14        ASSIGN                                                   !6, $17
   15    15        SUB                                              ~19     !6, !2
         16        IS_SMALLER                                               86400, ~19
         17      > JMPZ                                                     ~20, ->19
   16    18    >   PRE_INC                                                  !1
   18    19    >   FETCH_DIM_W                                      $22     !7, !1
         20        ASSIGN_DIM                                               $22
         21        OP_DATA                                                  !6
   19    22        ASSIGN                                                   !2, !6
   11    23      > JMP                                                      ->5
         24    >   FE_FREE                                                  $14
   22    25      > FE_RESET_R                                       $25     !7, ->59
         26    > > FE_FETCH_R                                               $25, !8, ->59
   23    27    >   COUNT                                            ~26     !8
         28        IS_SMALLER                                               1, ~26
         29      > JMPZ                                                     ~27, ->49
   24    30    >   INIT_FCALL                                               'date'
         31        SEND_VAR                                                 !3
         32        INIT_FCALL                                               'min'
         33        SEND_VAR                                                 !8
         34        DO_ICALL                                         $29     
         35        SEND_VAR                                                 $29
         36        DO_ICALL                                         $30     
         37        CONCAT                                           ~31     $30, '+-+'
         38        INIT_FCALL                                               'date'
         39        SEND_VAR                                                 !3
         40        INIT_FCALL                                               'max'
         41        SEND_VAR                                                 !8
         42        DO_ICALL                                         $32     
         43        SEND_VAR                                                 $32
         44        DO_ICALL                                         $33     
         45        CONCAT                                           ~34     ~31, $33
         46        ASSIGN_DIM                                               !9
         47        OP_DATA                                                  ~34
   23    48      > JMP                                                      ->58
   26    49    >   INIT_FCALL                                               'date'
         50        SEND_VAR                                                 !3
         51        INIT_FCALL                                               'min'
         52        SEND_VAR                                                 !8
         53        DO_ICALL                                         $36     
         54        SEND_VAR                                                 $36
         55        DO_ICALL                                         $37     
         56        ASSIGN_DIM                                               !9
         57        OP_DATA                                                  $37
   22    58    > > JMP                                                      ->26
         59    >   FE_FREE                                                  $25
   29    60        INIT_FCALL                                               'var_dump'
         61        SEND_VAR                                                 !9
         62        DO_ICALL                                                 
         63      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.95 ms | 1021 KiB | 19 Q