3v4l.org

run code in 500+ PHP versions simultaneously
<?php $time_start = [ 0 => '22:00:00', 1 => '03:00:00', ]; $time_end = [ 0 => '02:00:00', 1 => '08:00:00', ]; $logs = [ 0 => '2019-07-09 22:00:00', 1 => '2019-07-10 02:00:00', 2 => '2019-07-10 03:00:00', 3 => '2019-07-10 08:00:00', ]; $time = []; $diff = 0; for ($j = 0; $j < count($logs); $j = $j + 2) { $attendance_start = date("Y-m-d", strtotime($logs[$j])); $attendance_end = date("Y-m-d", strtotime($logs[$j + 1])); for ($i = 0; $i < count($time_start); $i++) { $time_starts = date('Y-m-d H:i:s', strtotime("$attendance_start " . $time_start[$i] . "")); $time_ends = date('Y-m-d H:i:s', strtotime("$attendance_end " . $time_end[$i] . "")); if ($logs[$j] >= $time_starts && $logs[$j + 1] <= $time_ends) { array_push($time, $logs[$j], $logs[$j + 1]); $diff += (round((strtotime($logs[$j + 1]) - strtotime($logs[$j])) / 3600, 1)); break; } } } echo $diff . " Hours";die;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 93
Branch analysis from position: 93
2 jumps found. (Code = 44) Position 1 = 96, Position 2 = 7
Branch analysis from position: 96
1 jumps found. (Code = 61) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 88
Branch analysis from position: 88
2 jumps found. (Code = 44) Position 1 = 91, Position 2 = 28
Branch analysis from position: 91
2 jumps found. (Code = 44) Position 1 = 96, Position 2 = 7
Branch analysis from position: 96
Branch analysis from position: 7
Branch analysis from position: 28
2 jumps found. (Code = 46) Position 1 = 57, Position 2 = 61
Branch analysis from position: 57
2 jumps found. (Code = 43) Position 1 = 62, Position 2 = 87
Branch analysis from position: 62
1 jumps found. (Code = 42) Position 1 = 91
Branch analysis from position: 91
Branch analysis from position: 87
2 jumps found. (Code = 44) Position 1 = 91, Position 2 = 28
Branch analysis from position: 91
Branch analysis from position: 28
Branch analysis from position: 61
filename:       /in/NHGg0
function name:  (null)
number of ops:  101
compiled vars:  !0 = $time_start, !1 = $time_end, !2 = $logs, !3 = $time, !4 = $diff, !5 = $j, !6 = $attendance_start, !7 = $attendance_end, !8 = $i, !9 = $time_starts, !10 = $time_ends
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, <array>
    6     1        ASSIGN                                                       !1, <array>
   10     2        ASSIGN                                                       !2, <array>
   16     3        ASSIGN                                                       !3, <array>
   17     4        ASSIGN                                                       !4, 0
   18     5        ASSIGN                                                       !5, 0
          6      > JMP                                                          ->93
   19     7    >   INIT_FCALL                                                   'date'
          8        SEND_VAL                                                     'Y-m-d'
          9        INIT_FCALL                                                   'strtotime'
         10        FETCH_DIM_R                                          ~17     !2, !5
         11        SEND_VAL                                                     ~17
         12        DO_ICALL                                             $18     
         13        SEND_VAR                                                     $18
         14        DO_ICALL                                             $19     
         15        ASSIGN                                                       !6, $19
   20    16        INIT_FCALL                                                   'date'
         17        SEND_VAL                                                     'Y-m-d'
         18        INIT_FCALL                                                   'strtotime'
         19        ADD                                                  ~21     !5, 1
         20        FETCH_DIM_R                                          ~22     !2, ~21
         21        SEND_VAL                                                     ~22
         22        DO_ICALL                                             $23     
         23        SEND_VAR                                                     $23
         24        DO_ICALL                                             $24     
         25        ASSIGN                                                       !7, $24
   21    26        ASSIGN                                                       !8, 0
         27      > JMP                                                          ->88
   22    28    >   INIT_FCALL                                                   'date'
         29        SEND_VAL                                                     'Y-m-d+H%3Ai%3As'
         30        INIT_FCALL                                                   'strtotime'
         31        NOP                                                          
         32        FAST_CONCAT                                          ~27     !6, '+'
         33        FETCH_DIM_R                                          ~28     !0, !8
         34        CONCAT                                               ~29     ~27, ~28
         35        CONCAT                                               ~30     ~29, ''
         36        SEND_VAL                                                     ~30
         37        DO_ICALL                                             $31     
         38        SEND_VAR                                                     $31
         39        DO_ICALL                                             $32     
         40        ASSIGN                                                       !9, $32
   23    41        INIT_FCALL                                                   'date'
         42        SEND_VAL                                                     'Y-m-d+H%3Ai%3As'
         43        INIT_FCALL                                                   'strtotime'
         44        NOP                                                          
         45        FAST_CONCAT                                          ~34     !7, '+'
         46        FETCH_DIM_R                                          ~35     !1, !8
         47        CONCAT                                               ~36     ~34, ~35
         48        CONCAT                                               ~37     ~36, ''
         49        SEND_VAL                                                     ~37
         50        DO_ICALL                                             $38     
         51        SEND_VAR                                                     $38
         52        DO_ICALL                                             $39     
         53        ASSIGN                                                       !10, $39
   24    54        FETCH_DIM_R                                          ~41     !2, !5
         55        IS_SMALLER_OR_EQUAL                                  ~42     !9, ~41
         56      > JMPZ_EX                                              ~42     ~42, ->61
         57    >   ADD                                                  ~43     !5, 1
         58        FETCH_DIM_R                                          ~44     !2, ~43
         59        IS_SMALLER_OR_EQUAL                                  ~45     ~44, !10
         60        BOOL                                                 ~42     ~45
         61    > > JMPZ                                                         ~42, ->87
   25    62    >   INIT_FCALL                                                   'array_push'
         63        SEND_REF                                                     !3
         64        FETCH_DIM_R                                          ~46     !2, !5
         65        SEND_VAL                                                     ~46
         66        ADD                                                  ~47     !5, 1
         67        FETCH_DIM_R                                          ~48     !2, ~47
         68        SEND_VAL                                                     ~48
         69        DO_ICALL                                                     
   26    70        INIT_FCALL                                                   'round'
         71        INIT_FCALL                                                   'strtotime'
         72        ADD                                                  ~50     !5, 1
         73        FETCH_DIM_R                                          ~51     !2, ~50
         74        SEND_VAL                                                     ~51
         75        DO_ICALL                                             $52     
         76        INIT_FCALL                                                   'strtotime'
         77        FETCH_DIM_R                                          ~53     !2, !5
         78        SEND_VAL                                                     ~53
         79        DO_ICALL                                             $54     
         80        SUB                                                  ~55     $52, $54
         81        DIV                                                  ~56     ~55, 3600
         82        SEND_VAL                                                     ~56
         83        SEND_VAL                                                     1
         84        DO_ICALL                                             $57     
         85        ASSIGN_OP                                         1          !4, $57
   27    86      > JMP                                                          ->91
   21    87    >   PRE_INC                                                      !8
         88    >   COUNT                                                ~60     !0
         89        IS_SMALLER                                                   !8, ~60
         90      > JMPNZ                                                        ~61, ->28
   18    91    >   ADD                                                  ~62     !5, 2
         92        ASSIGN                                                       !5, ~62
         93    >   COUNT                                                ~64     !2
         94        IS_SMALLER                                                   !5, ~64
         95      > JMPNZ                                                        ~65, ->7
   31    96    >   CONCAT                                               ~66     !4, '+Hours'
         97        ECHO                                                         ~66
         98      > INIT_FCALL                                                   'exit'
         99*       DO_ICALL                                                     
   32   100*     > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
176.54 ms | 2055 KiB | 18 Q