3v4l.org

run code in 500+ PHP versions simultaneously
<?php $timeslot = []; $timeslot[] = '07:00-08:00'; $timeslot[] = '07:15-07:30'; $timeslot[] = '07:30-08:30'; $timeslot[] = '10:45-11:45'; $min_time = -1; $max_time = -1; $total_minutes = 0; foreach($timeslot as $slot){ list($start_time,$end_time) = explode("-",$slot); $start_time = explode(":",$start_time); $start_time = intval($start_time[0]) * 60 + intval($start_time[1]); // converting to minutes $end_time = explode(":",$end_time); $end_time = intval($end_time[0]) * 60 + intval($end_time[1]);// converting to minutes if($min_time == -1){// or max time for that matter (just basic initialization of these 2 variables) $min_time = $start_time; $max_time = $end_time; $total_minutes += $max_time - $min_time; }else{ if($start_time >= $max_time) $total_minutes += $end_time - $start_time; else if($start_time < $max_time && $end_time > $max_time) $total_minutes += $end_time - $max_time; $min_time = min($min_time,$start_time); $max_time = max($max_time,$end_time); } } echo intval($total_minutes / 60),":",($total_minutes % 60)," hrs";
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 71
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 71
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 54
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 70
Branch analysis from position: 70
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 54
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 59
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 66
Branch analysis from position: 66
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 59
2 jumps found. (Code = 46) Position 1 = 61, Position 2 = 63
Branch analysis from position: 61
2 jumps found. (Code = 43) Position 1 = 64, Position 2 = 66
Branch analysis from position: 64
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 66
Branch analysis from position: 63
Branch analysis from position: 71
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 71
filename:       /in/nvjDq
function name:  (null)
number of ops:  80
compiled vars:  !0 = $timeslot, !1 = $min_time, !2 = $max_time, !3 = $total_minutes, !4 = $slot, !5 = $start_time, !6 = $end_time
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
    4     1        ASSIGN_DIM                                                   !0
          2        OP_DATA                                                      '07%3A00-08%3A00'
    5     3        ASSIGN_DIM                                                   !0
          4        OP_DATA                                                      '07%3A15-07%3A30'
    6     5        ASSIGN_DIM                                                   !0
          6        OP_DATA                                                      '07%3A30-08%3A30'
    7     7        ASSIGN_DIM                                                   !0
          8        OP_DATA                                                      '10%3A45-11%3A45'
    9     9        ASSIGN                                                       !1, -1
   10    10        ASSIGN                                                       !2, -1
   11    11        ASSIGN                                                       !3, 0
   13    12      > FE_RESET_R                                           $15     !0, ->71
         13    > > FE_FETCH_R                                                   $15, !4, ->71
   14    14    >   INIT_FCALL                                                   'explode'
         15        SEND_VAL                                                     '-'
         16        SEND_VAR                                                     !4
         17        DO_ICALL                                             $16     
         18        FETCH_LIST_R                                         $17     $16, 0
         19        ASSIGN                                                       !5, $17
         20        FETCH_LIST_R                                         $19     $16, 1
         21        ASSIGN                                                       !6, $19
         22        FREE                                                         $16
   16    23        INIT_FCALL                                                   'explode'
         24        SEND_VAL                                                     '%3A'
         25        SEND_VAR                                                     !5
         26        DO_ICALL                                             $21     
         27        ASSIGN                                                       !5, $21
   17    28        FETCH_DIM_R                                          ~23     !5, 0
         29        CAST                                              4  ~24     ~23
         30        MUL                                                  ~25     ~24, 60
         31        FETCH_DIM_R                                          ~26     !5, 1
         32        CAST                                              4  ~27     ~26
         33        ADD                                                  ~28     ~25, ~27
         34        ASSIGN                                                       !5, ~28
   18    35        INIT_FCALL                                                   'explode'
         36        SEND_VAL                                                     '%3A'
         37        SEND_VAR                                                     !6
         38        DO_ICALL                                             $30     
         39        ASSIGN                                                       !6, $30
   19    40        FETCH_DIM_R                                          ~32     !6, 0
         41        CAST                                              4  ~33     ~32
         42        MUL                                                  ~34     ~33, 60
         43        FETCH_DIM_R                                          ~35     !6, 1
         44        CAST                                              4  ~36     ~35
         45        ADD                                                  ~37     ~34, ~36
         46        ASSIGN                                                       !6, ~37
   22    47        IS_EQUAL                                                     !1, -1
         48      > JMPZ                                                         ~39, ->54
   23    49    >   ASSIGN                                                       !1, !5
   24    50        ASSIGN                                                       !2, !6
   25    51        SUB                                                  ~42     !2, !1
         52        ASSIGN_OP                                         1          !3, ~42
   22    53      > JMP                                                          ->70
   27    54    >   IS_SMALLER_OR_EQUAL                                          !2, !5
         55      > JMPZ                                                         ~44, ->59
         56    >   SUB                                                  ~45     !6, !5
         57        ASSIGN_OP                                         1          !3, ~45
         58      > JMP                                                          ->66
   28    59    >   IS_SMALLER                                           ~47     !5, !2
         60      > JMPZ_EX                                              ~47     ~47, ->63
         61    >   IS_SMALLER                                           ~48     !2, !6
         62        BOOL                                                 ~47     ~48
         63    > > JMPZ                                                         ~47, ->66
         64    >   SUB                                                  ~49     !6, !2
         65        ASSIGN_OP                                         1          !3, ~49
   30    66    >   FRAMELESS_ICALL_2                min                 ~51     !1, !5
         67        ASSIGN                                                       !1, ~51
   31    68        FRAMELESS_ICALL_2                max                 ~53     !2, !6
         69        ASSIGN                                                       !2, ~53
   13    70    > > JMP                                                          ->13
         71    >   FE_FREE                                                      $15
   35    72        DIV                                                  ~55     !3, 60
         73        CAST                                              4  ~56     ~55
         74        ECHO                                                         ~56
         75        ECHO                                                         '%3A'
         76        MOD                                                  ~57     !3, 60
         77        ECHO                                                         ~57
         78        ECHO                                                         '+hrs'
         79      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
170.09 ms | 2191 KiB | 14 Q