3v4l.org

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

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

End of function %00%7Bclosure%7D%2Fin%2FoHW1A%3A12%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.07 ms | 1409 KiB | 23 Q