3v4l.org

run code in 500+ PHP versions simultaneously
<?php $data = [ [ 'name' => 'Event A', 'date' => '2023-03-1' ], [ 'name' => 'Event B', 'date' => '2023-03-2' ], [ 'name' => 'Event C', 'date' => '2023-03-3' ], [ 'name' => 'Event D', 'date' => '2023-03-7' ], [ 'name' => 'Event E', 'date' => '2023-03-9' ], ]; $start_d = null; $curr_d = null; $groups = []; foreach($data as $d){ $dd = DateTime::createFromFormat('!Y-m-d', $d['date']); if($start_d == null){ $start_d = $curr_d = $dd; }else{ $diff = $dd->diff($curr_d) ; if($diff->y === 0 && $diff->m === 0 && $diff->d === 1){ $curr_d = $dd; }else{ $groups[] = [$start_d->format('d'), $curr_d->format('d')]; $start_d = $curr_d = $dd; } } } $groups[] = [$start_d->format('d'), $curr_d->format('d')]; echo implode(" , ", array_map(fn($v) => implode(" - ", array_unique($v)), $groups)), " / ", $start_d->format('m'), " / ", $start_d->format('Y');
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 47
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 47
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 17
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 17
2 jumps found. (Code = 46) Position 1 = 24, Position 2 = 27
Branch analysis from position: 24
2 jumps found. (Code = 46) Position 1 = 28, Position 2 = 31
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 34
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 31
Branch analysis from position: 27
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
filename:       /in/0KlOB
function name:  (null)
number of ops:  76
compiled vars:  !0 = $data, !1 = $start_d, !2 = $curr_d, !3 = $groups, !4 = $d, !5 = $dd, !6 = $diff
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   27     1        ASSIGN                                                       !1, null
   28     2        ASSIGN                                                       !2, null
   30     3        ASSIGN                                                       !3, <array>
   32     4      > FE_RESET_R                                           $11     !0, ->47
          5    > > FE_FETCH_R                                                   $11, !4, ->47
   33     6    >   INIT_STATIC_METHOD_CALL                                      'DateTime', 'createFromFormat'
          7        SEND_VAL                                                     '%21Y-m-d'
          8        FETCH_DIM_R                                          ~12     !4, 'date'
          9        SEND_VAL                                                     ~12
         10        DO_FCALL                                          0  $13     
         11        ASSIGN                                                       !5, $13
   34    12        IS_EQUAL                                                     !1, null
         13      > JMPZ                                                         ~15, ->17
   35    14    >   ASSIGN                                               ~16     !2, !5
         15        ASSIGN                                                       !1, ~16
   34    16      > JMP                                                          ->46
   37    17    >   INIT_METHOD_CALL                                             !5, 'diff'
         18        SEND_VAR_EX                                                  !2
         19        DO_FCALL                                          0  $18     
         20        ASSIGN                                                       !6, $18
   38    21        FETCH_OBJ_R                                          ~20     !6, 'y'
         22        IS_IDENTICAL                                         ~21     ~20, 0
         23      > JMPZ_EX                                              ~21     ~21, ->27
         24    >   FETCH_OBJ_R                                          ~22     !6, 'm'
         25        IS_IDENTICAL                                         ~23     ~22, 0
         26        BOOL                                                 ~21     ~23
         27    > > JMPZ_EX                                              ~21     ~21, ->31
         28    >   FETCH_OBJ_R                                          ~24     !6, 'd'
         29        IS_IDENTICAL                                         ~25     ~24, 1
         30        BOOL                                                 ~21     ~25
         31    > > JMPZ                                                         ~21, ->34
   39    32    >   ASSIGN                                                       !2, !5
   38    33      > JMP                                                          ->46
   41    34    >   INIT_METHOD_CALL                                             !1, 'format'
         35        SEND_VAL_EX                                                  'd'
         36        DO_FCALL                                          0  $28     
         37        INIT_ARRAY                                           ~29     $28
         38        INIT_METHOD_CALL                                             !2, 'format'
         39        SEND_VAL_EX                                                  'd'
         40        DO_FCALL                                          0  $30     
         41        ADD_ARRAY_ELEMENT                                    ~29     $30
         42        ASSIGN_DIM                                                   !3
         43        OP_DATA                                                      ~29
   42    44        ASSIGN                                               ~31     !2, !5
         45        ASSIGN                                                       !1, ~31
   32    46    > > JMP                                                          ->5
         47    >   FE_FREE                                                      $11
   47    48        INIT_METHOD_CALL                                             !1, 'format'
         49        SEND_VAL_EX                                                  'd'
         50        DO_FCALL                                          0  $34     
         51        INIT_ARRAY                                           ~35     $34
         52        INIT_METHOD_CALL                                             !2, 'format'
         53        SEND_VAL_EX                                                  'd'
         54        DO_FCALL                                          0  $36     
         55        ADD_ARRAY_ELEMENT                                    ~35     $36
         56        ASSIGN_DIM                                                   !3
         57        OP_DATA                                                      ~35
   49    58        INIT_FCALL                                                   'array_map'
         59        DECLARE_LAMBDA_FUNCTION                              ~37     [0]
         60        SEND_VAL                                                     ~37
         61        SEND_VAR                                                     !3
         62        DO_ICALL                                             $38     
         63        FRAMELESS_ICALL_2                implode             ~39     '+%2C+', $38
         64        ECHO                                                         ~39
         65        ECHO                                                         '+%2F+'
         66        INIT_METHOD_CALL                                             !1, 'format'
         67        SEND_VAL_EX                                                  'm'
         68        DO_FCALL                                          0  $40     
         69        ECHO                                                         $40
         70        ECHO                                                         '+%2F+'
         71        INIT_METHOD_CALL                                             !1, 'format'
         72        SEND_VAL_EX                                                  'Y'
         73        DO_FCALL                                          0  $41     
         74        ECHO                                                         $41
         75      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0KlOB
function name:  {closure:/in/0KlOB:49}
number of ops:  7
compiled vars:  !0 = $v
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
          0  E >   RECV                                                 !0      
          1        INIT_FCALL                                                   'array_unique'
          2        SEND_VAR                                                     !0
          3        DO_ICALL                                             $1      
          4        FRAMELESS_ICALL_2                implode             ~2      '+-+', $1
          5      > RETURN                                                       ~2
          6*     > RETURN                                                       null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
220.75 ms | 1776 KiB | 15 Q