3v4l.org

run code in 500+ PHP versions simultaneously
<?php $array = [ '2020-02-07' => ['09:00' => 1500, '10:30' => 1500, '11:00' => 1500, '11:30' => 0], '2020-02-08' => ['09:00' => 1500, '09:30' => 1500, '11:00' => 1500], ]; $result = []; $f = fn($p) => date('H:i', $p); foreach ($array as $k => $v) { $v = array_map(fn($a) => strtotime($a), array_keys($v)); for ($i = 0; $i < count($v); $i++) { [$a, $b] = [$v[$i], &$a]; while (isset($v[$i + 1]) && $v[$i + 1] - $v[$i] === 1800) [$b = $v[$i + 1], $i++]; $result[] = ['date' => $k, 'range' => $a == $b ? $f($a) : $f($a) .' - '. $f($b)]; } } print_r($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 69
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 69
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 65
Branch analysis from position: 65
2 jumps found. (Code = 44) Position 1 = 68, Position 2 = 18
Branch analysis from position: 68
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
2 jumps found. (Code = 46) Position 1 = 37, Position 2 = 43
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 27
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 52
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
2 jumps found. (Code = 44) Position 1 = 68, Position 2 = 18
Branch analysis from position: 68
Branch analysis from position: 18
Branch analysis from position: 52
2 jumps found. (Code = 44) Position 1 = 68, Position 2 = 18
Branch analysis from position: 68
Branch analysis from position: 18
Branch analysis from position: 27
2 jumps found. (Code = 46) Position 1 = 37, Position 2 = 43
Branch analysis from position: 37
Branch analysis from position: 43
Branch analysis from position: 43
Branch analysis from position: 69
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 69
filename:       /in/qjNjT
function name:  (null)
number of ops:  74
compiled vars:  !0 = $array, !1 = $result, !2 = $f, !3 = $v, !4 = $k, !5 = $i, !6 = $a, !7 = $b
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
    8     1        ASSIGN                                                       !1, <array>
    9     2        DECLARE_LAMBDA_FUNCTION                              ~10     [0]
          3        ASSIGN                                                       !2, ~10
   11     4      > FE_RESET_R                                           $12     !0, ->69
          5    > > FE_FETCH_R                                           ~13     $12, !3, ->69
          6    >   ASSIGN                                                       !4, ~13
   13     7        INIT_FCALL                                                   'array_map'
          8        DECLARE_LAMBDA_FUNCTION                              ~15     [1]
          9        SEND_VAL                                                     ~15
         10        INIT_FCALL                                                   'array_keys'
         11        SEND_VAR                                                     !3
         12        DO_ICALL                                             $16     
         13        SEND_VAR                                                     $16
         14        DO_ICALL                                             $17     
         15        ASSIGN                                                       !3, $17
   14    16        ASSIGN                                                       !5, 0
         17      > JMP                                                          ->65
   15    18    >   FETCH_DIM_R                                          ~20     !3, !5
         19        INIT_ARRAY                                           ~21     ~20
         20        ADD_ARRAY_ELEMENT                                    ~21     !6
         21        FETCH_LIST_R                                         $22     ~21, 0
         22        ASSIGN                                                       !6, $22
         23        FETCH_LIST_R                                         $24     ~21, 1
         24        ASSIGN                                                       !7, $24
         25        FREE                                                         ~21
   16    26      > JMP                                                          ->34
         27    >   ADD                                                  ~26     !5, 1
         28        FETCH_DIM_R                                          ~27     !3, ~26
         29        ASSIGN                                               ~28     !7, ~27
         30        INIT_ARRAY                                           ~29     ~28
         31        POST_INC                                             ~30     !5
         32        ADD_ARRAY_ELEMENT                                    ~29     ~30
         33        FREE                                                         ~29
         34    >   ADD                                                  ~31     !5, 1
         35        ISSET_ISEMPTY_DIM_OBJ                             0  ~32     !3, ~31
         36      > JMPZ_EX                                              ~32     ~32, ->43
         37    >   ADD                                                  ~33     !5, 1
         38        FETCH_DIM_R                                          ~34     !3, ~33
         39        FETCH_DIM_R                                          ~35     !3, !5
         40        SUB                                                  ~36     ~34, ~35
         41        IS_IDENTICAL                                         ~37     ~36, 1800
         42        BOOL                                                 ~32     ~37
         43    > > JMPNZ                                                        ~32, ->27
   17    44    >   INIT_ARRAY                                           ~39     !4, 'date'
         45        IS_EQUAL                                                     !6, !7
         46      > JMPZ                                                         ~40, ->52
         47    >   INIT_DYNAMIC_CALL                                            !2
         48        SEND_VAR_EX                                                  !6
         49        DO_FCALL                                          0  $41     
         50        QM_ASSIGN                                            ~42     $41
         51      > JMP                                                          ->61
         52    >   INIT_DYNAMIC_CALL                                            !2
         53        SEND_VAR_EX                                                  !6
         54        DO_FCALL                                          0  $43     
         55        CONCAT                                               ~44     $43, '+-+'
         56        INIT_DYNAMIC_CALL                                            !2
         57        SEND_VAR_EX                                                  !7
         58        DO_FCALL                                          0  $45     
         59        CONCAT                                               ~46     ~44, $45
         60        QM_ASSIGN                                            ~42     ~46
         61    >   ADD_ARRAY_ELEMENT                                    ~39     ~42, 'range'
         62        ASSIGN_DIM                                                   !1
         63        OP_DATA                                                      ~39
   14    64        PRE_INC                                                      !5
         65    >   COUNT                                                ~48     !3
         66        IS_SMALLER                                                   !5, ~48
         67      > JMPNZ                                                        ~49, ->18
   11    68    > > JMP                                                          ->5
         69    >   FE_FREE                                                      $12
   21    70        INIT_FCALL                                                   'print_r'
         71        SEND_VAR                                                     !1
         72        DO_ICALL                                                     
         73      > 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/qjNjT
function name:  {closure:/in/qjNjT:9}
number of ops:  7
compiled vars:  !0 = $p
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    9     0  E >   RECV                                                 !0      
          1        INIT_FCALL                                                   'date'
          2        SEND_VAL                                                     'H%3Ai'
          3        SEND_VAR                                                     !0
          4        DO_ICALL                                             $1      
          5      > RETURN                                                       $1
          6*     > RETURN                                                       null

End of Dynamic Function 0

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

End of Dynamic Function 1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
155.3 ms | 1622 KiB | 13 Q