3v4l.org

run code in 500+ PHP versions simultaneously
<?php $data =array( array ( 'ticketCreated' => '2020-02-03 15:59:30','ticketCompletedOn' => '2020-02-04 09:53:35'), array ( 'ticketCreated' => '2020-02-04 14:00:00', 'ticketCompletedOn' => '2020-02-04 14:36:00') ); $sum_time = 0; foreach($data as $details){ $start_time = new DateTime($details['ticketCreated']); $end_time = new DateTime($details['ticketCompletedOn']); $end_of_day = new DateTime($start_time->format('Y-m-d') . ' 17:00:00'); // since a day ends at 17:00 do{ $diff = $end_time->diff($start_time); $diff2 = $end_of_day->diff($start_time); if($end_time->format('Y-m-d') === $start_time->format('Y-m-d')){ // meaning finished on the same day $sum_time += ($diff->h * 60) + ($diff->i) + ($diff->s / 60); }else if(!in_array($end_of_day->format('N'),[6,7])){ // skipping Saturdays and Sundays $sum_time += ($diff2->h * 60) + ($diff2->i) + ($diff2->s / 60); // add the day's offset(480 minutes) } $end_of_day->add(new DateInterval('P1D')); $start_time = new DateTime($end_of_day->format('Y-m-d') . ' 09:00:00'); // start time for next day which is 09:00 }while($start_time <= $end_time); } $avg = $sum_time / count($data); echo "$avg minutes",PHP_EOL;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 80
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 80
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 40, Position 2 = 49
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 63
Branch analysis from position: 63
2 jumps found. (Code = 44) Position 1 = 79, Position 2 = 24
Branch analysis from position: 79
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 24
Branch analysis from position: 49
2 jumps found. (Code = 43) Position 1 = 55, Position 2 = 63
Branch analysis from position: 55
2 jumps found. (Code = 44) Position 1 = 79, Position 2 = 24
Branch analysis from position: 79
Branch analysis from position: 24
Branch analysis from position: 63
Branch analysis from position: 80
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 80
filename:       /in/gpFt4
function name:  (null)
number of ops:  89
compiled vars:  !0 = $data, !1 = $sum_time, !2 = $details, !3 = $start_time, !4 = $end_time, !5 = $end_of_day, !6 = $diff, !7 = $diff2, !8 = $avg
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
    8     1        ASSIGN                                                       !1, 0
   10     2      > FE_RESET_R                                           $11     !0, ->80
          3    > > FE_FETCH_R                                                   $11, !2, ->80
   11     4    >   NEW                                                  $12     'DateTime'
          5        CHECK_FUNC_ARG                                               
          6        FETCH_DIM_FUNC_ARG                                   $13     !2, 'ticketCreated'
          7        SEND_FUNC_ARG                                                $13
          8        DO_FCALL                                          0          
          9        ASSIGN                                                       !3, $12
   12    10        NEW                                                  $16     'DateTime'
         11        CHECK_FUNC_ARG                                               
         12        FETCH_DIM_FUNC_ARG                                   $17     !2, 'ticketCompletedOn'
         13        SEND_FUNC_ARG                                                $17
         14        DO_FCALL                                          0          
         15        ASSIGN                                                       !4, $16
   13    16        NEW                                                  $20     'DateTime'
         17        INIT_METHOD_CALL                                             !3, 'format'
         18        SEND_VAL_EX                                                  'Y-m-d'
         19        DO_FCALL                                          0  $21     
         20        CONCAT                                               ~22     $21, '+17%3A00%3A00'
         21        SEND_VAL_EX                                                  ~22
         22        DO_FCALL                                          0          
         23        ASSIGN                                                       !5, $20
   16    24    >   INIT_METHOD_CALL                                             !4, 'diff'
         25        SEND_VAR_EX                                                  !3
         26        DO_FCALL                                          0  $25     
         27        ASSIGN                                                       !6, $25
   17    28        INIT_METHOD_CALL                                             !5, 'diff'
         29        SEND_VAR_EX                                                  !3
         30        DO_FCALL                                          0  $27     
         31        ASSIGN                                                       !7, $27
   18    32        INIT_METHOD_CALL                                             !4, 'format'
         33        SEND_VAL_EX                                                  'Y-m-d'
         34        DO_FCALL                                          0  $29     
         35        INIT_METHOD_CALL                                             !3, 'format'
         36        SEND_VAL_EX                                                  'Y-m-d'
         37        DO_FCALL                                          0  $30     
         38        IS_IDENTICAL                                                 $29, $30
         39      > JMPZ                                                         ~31, ->49
   19    40    >   FETCH_OBJ_R                                          ~32     !6, 'h'
         41        MUL                                                  ~33     ~32, 60
         42        FETCH_OBJ_R                                          ~34     !6, 'i'
         43        ADD                                                  ~35     ~33, ~34
         44        FETCH_OBJ_R                                          ~36     !6, 's'
         45        DIV                                                  ~37     ~36, 60
         46        ADD                                                  ~38     ~35, ~37
         47        ASSIGN_OP                                         1          !1, ~38
   18    48      > JMP                                                          ->63
   20    49    >   INIT_METHOD_CALL                                             !5, 'format'
         50        SEND_VAL_EX                                                  'N'
         51        DO_FCALL                                          0  $40     
         52        FRAMELESS_ICALL_2                in_array            ~41     $40, <array>
         53        BOOL_NOT                                             ~42     ~41
         54      > JMPZ                                                         ~42, ->63
   21    55    >   FETCH_OBJ_R                                          ~43     !7, 'h'
         56        MUL                                                  ~44     ~43, 60
         57        FETCH_OBJ_R                                          ~45     !7, 'i'
         58        ADD                                                  ~46     ~44, ~45
         59        FETCH_OBJ_R                                          ~47     !7, 's'
         60        DIV                                                  ~48     ~47, 60
         61        ADD                                                  ~49     ~46, ~48
         62        ASSIGN_OP                                         1          !1, ~49
   24    63    >   INIT_METHOD_CALL                                             !5, 'add'
         64        NEW                                                  $51     'DateInterval'
         65        SEND_VAL_EX                                                  'P1D'
         66        DO_FCALL                                          0          
         67        SEND_VAR_NO_REF_EX                                           $51
         68        DO_FCALL                                          0          
   25    69        NEW                                                  $54     'DateTime'
         70        INIT_METHOD_CALL                                             !5, 'format'
         71        SEND_VAL_EX                                                  'Y-m-d'
         72        DO_FCALL                                          0  $55     
         73        CONCAT                                               ~56     $55, '+09%3A00%3A00'
         74        SEND_VAL_EX                                                  ~56
         75        DO_FCALL                                          0          
         76        ASSIGN                                                       !3, $54
   27    77        IS_SMALLER_OR_EQUAL                                          !3, !4
         78      > JMPNZ                                                        ~59, ->24
   10    79    > > JMP                                                          ->3
         80    >   FE_FREE                                                      $11
   31    81        COUNT                                                ~60     !0
         82        DIV                                                  ~61     !1, ~60
         83        ASSIGN                                                       !8, ~61
   33    84        NOP                                                          
         85        FAST_CONCAT                                          ~63     !8, '+minutes'
         86        ECHO                                                         ~63
         87        ECHO                                                         '%0A'
   34    88      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
163.45 ms | 2085 KiB | 13 Q