3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getRoundedCutoff ($t) { $time = explode(':', $t); if ( $time[2] > 30 ) { $time[1] = intval($time[1]) + 1; } if ( $time[1] >= 60 ) { $time[1] = '00'; $time[0] = $time[0] + 1; } $time[2] = '00'; $rmin = $time[1] % 15; $dt = new DateTime( implode(':', $time) ); if ( $rmin > 7 ) { $dt->add(new DateInterval('PT'.(15-$rmin).'M')); } else { $dt->sub(new DateInterval('PT'.$rmin.'M')); } return $dt->format('H:i:s'); } $times = array( '10:52:00', '10:52:59', '10:53:00', '10:50:00', '10:50:14', '10:50:59', '10:50:45', '01:12:00', '01:05:00', '01:58:00', '01:58:59', '01:59:59', '01:01:00', ); foreach ($times as $time) { var_dump($time.' -> '.getRoundedCutoff($time)); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 12
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 12
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/sWnTr
function name:  (null)
number of ops:  14
compiled vars:  !0 = $times, !1 = $time
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   ASSIGN                                                   !0, <array>
   42     1      > FE_RESET_R                                       $3      !0, ->12
          2    > > FE_FETCH_R                                               $3, !1, ->12
   43     3    >   INIT_FCALL                                               'var_dump'
          4        CONCAT                                           ~4      !1, '+-%3E+'
          5        INIT_FCALL                                               'getroundedcutoff'
          6        SEND_VAR                                                 !1
          7        DO_FCALL                                      0  $5      
          8        CONCAT                                           ~6      ~4, $5
          9        SEND_VAL                                                 ~6
         10        DO_ICALL                                                 
   42    11      > JMP                                                      ->2
         12    >   FE_FREE                                                  $3
   44    13      > RETURN                                                   1

Function getroundedcutoff:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 14
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 23
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 48
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 56
Branch analysis from position: 56
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
Branch analysis from position: 14
filename:       /in/sWnTr
function name:  getRoundedCutoff
number of ops:  61
compiled vars:  !0 = $t, !1 = $time, !2 = $rmin, !3 = $dt
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '%3A'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $4      
          5        ASSIGN                                                   !1, $4
    5     6        FETCH_DIM_R                                      ~6      !1, 2
          7        IS_SMALLER                                               30, ~6
          8      > JMPZ                                                     ~7, ->14
    6     9    >   FETCH_DIM_R                                      ~9      !1, 1
         10        CAST                                          4  ~10     ~9
         11        ADD                                              ~11     ~10, 1
         12        ASSIGN_DIM                                               !1, 1
         13        OP_DATA                                                  ~11
    8    14    >   FETCH_DIM_R                                      ~12     !1, 1
         15        IS_SMALLER_OR_EQUAL                                      60, ~12
         16      > JMPZ                                                     ~13, ->23
    9    17    >   ASSIGN_DIM                                               !1, 1
         18        OP_DATA                                                  '00'
   10    19        FETCH_DIM_R                                      ~16     !1, 0
         20        ADD                                              ~17     ~16, 1
         21        ASSIGN_DIM                                               !1, 0
         22        OP_DATA                                                  ~17
   12    23    >   ASSIGN_DIM                                               !1, 2
         24        OP_DATA                                                  '00'
   14    25        FETCH_DIM_R                                      ~19     !1, 1
         26        MOD                                              ~20     ~19, 15
         27        ASSIGN                                                   !2, ~20
   15    28        NEW                                              $22     'DateTime'
         29        INIT_FCALL                                               'implode'
         30        SEND_VAL                                                 '%3A'
         31        SEND_VAR                                                 !1
         32        DO_ICALL                                         $23     
         33        SEND_VAR_NO_REF_EX                                       $23
         34        DO_FCALL                                      0          
         35        ASSIGN                                                   !3, $22
   17    36        IS_SMALLER                                               7, !2
         37      > JMPZ                                                     ~26, ->48
   18    38    >   INIT_METHOD_CALL                                         !3, 'add'
         39        NEW                                              $27     'DateInterval'
         40        SUB                                              ~28     15, !2
         41        CONCAT                                           ~29     'PT', ~28
         42        CONCAT                                           ~30     ~29, 'M'
         43        SEND_VAL_EX                                              ~30
         44        DO_FCALL                                      0          
         45        SEND_VAR_NO_REF_EX                                       $27
         46        DO_FCALL                                      0          
         47      > JMP                                                      ->56
   20    48    >   INIT_METHOD_CALL                                         !3, 'sub'
         49        NEW                                              $33     'DateInterval'
         50        CONCAT                                           ~34     'PT', !2
         51        CONCAT                                           ~35     ~34, 'M'
         52        SEND_VAL_EX                                              ~35
         53        DO_FCALL                                      0          
         54        SEND_VAR_NO_REF_EX                                       $33
         55        DO_FCALL                                      0          
   23    56    >   INIT_METHOD_CALL                                         !3, 'format'
         57        SEND_VAL_EX                                              'H%3Ai%3As'
         58        DO_FCALL                                      0  $38     
         59      > RETURN                                                   $38
   24    60*     > RETURN                                                   null

End of function getroundedcutoff

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.95 ms | 1403 KiB | 20 Q