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; $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/SJ20Q
function name:  (null)
number of ops:  14
compiled vars:  !0 = $times, !1 = $time
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   ASSIGN                                                   !0, <array>
   36     1      > FE_RESET_R                                       $3      !0, ->12
          2    > > FE_FETCH_R                                               $3, !1, ->12
   37     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                                                 
   36    11      > JMP                                                      ->2
         12    >   FE_FREE                                                  $3
   38    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 = 29, Position 2 = 39
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/SJ20Q
function name:  getRoundedCutoff
number of ops:  52
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
          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
    6    14    >   ASSIGN_DIM                                               !1, 2
         15        OP_DATA                                                  '00'
    8    16        FETCH_DIM_R                                      ~13     !1, 1
         17        MOD                                              ~14     ~13, 15
         18        ASSIGN                                                   !2, ~14
    9    19        NEW                                              $16     'DateTime'
         20        INIT_FCALL                                               'implode'
         21        SEND_VAL                                                 '%3A'
         22        SEND_VAR                                                 !1
         23        DO_ICALL                                         $17     
         24        SEND_VAR_NO_REF_EX                                       $17
         25        DO_FCALL                                      0          
         26        ASSIGN                                                   !3, $16
   11    27        IS_SMALLER                                               7, !2
         28      > JMPZ                                                     ~20, ->39
   12    29    >   INIT_METHOD_CALL                                         !3, 'add'
         30        NEW                                              $21     'DateInterval'
         31        SUB                                              ~22     15, !2
         32        CONCAT                                           ~23     'PT', ~22
         33        CONCAT                                           ~24     ~23, 'M'
         34        SEND_VAL_EX                                              ~24
         35        DO_FCALL                                      0          
         36        SEND_VAR_NO_REF_EX                                       $21
         37        DO_FCALL                                      0          
         38      > JMP                                                      ->47
   14    39    >   INIT_METHOD_CALL                                         !3, 'sub'
         40        NEW                                              $27     'DateInterval'
         41        CONCAT                                           ~28     'PT', !2
         42        CONCAT                                           ~29     ~28, 'M'
         43        SEND_VAL_EX                                              ~29
         44        DO_FCALL                                      0          
         45        SEND_VAR_NO_REF_EX                                       $27
         46        DO_FCALL                                      0          
   17    47    >   INIT_METHOD_CALL                                         !3, 'format'
         48        SEND_VAL_EX                                              'H%3Ai%3As'
         49        DO_FCALL                                      0  $32     
         50      > RETURN                                                   $32
   18    51*     > RETURN                                                   null

End of function getroundedcutoff

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.35 ms | 1403 KiB | 20 Q