3v4l.org

run code in 300+ PHP versions simultaneously
<?php function formatHMS($inputval, $full = false, $timeFormat = '') { $minus = ''; if ($inputval < 0) { $minus = '- '; $inputval = -$inputval; } $unith = 3600; // Num of seconds in an Hour... $unitm = 60; // Num of seconds in a min... $hh = (int)($inputval / $unith); // '/' given value by num sec in hour... output = HOURS $ss_remaining = ($inputval - ($hh * 3600)); // '*' number of hours by seconds, then '-' from given value... output = REMAINING seconds $mm = (int)($ss_remaining / $unitm); // take remaining sec and devide by sec in a min... output = MINS $ss = ($ss_remaining - ($mm * 60)); // '*' number of mins by seconds, then '-' from remaining sec... output = REMAINING seconds. if (!$full && $ss > 30) { if ($mm === 60) { $hh++; $mm = 0; } } if ($timeFormat == '' || $timeFormat == 0) { if ($full) { return $minus . round($hh) . 'h ' . sprintf("%02d", round($mm)) . 'm ' . sprintf("%02d", round($ss)) . 's'; } if ($hh > 0) { return $minus . round($hh) . 'h ' . sprintf("%02d", round($mm)).'m'; } if ($mm > 0) { return $minus . sprintf("%02d", round($mm)).'m'; } return $minus . round($ss) . 's'; } switch ($timeFormat) { case 1: if ($full) { return $minus . sprintf("%02d", round($hh)) . ':' . sprintf("%02d", round($mm)) . ':' . sprintf("%02d", round($ss)); } return $minus . sprintf("%02d", round($hh)) . ':' . sprintf("%02d", round($mm)); case 2: return $minus . str_replace(".", ",", number_format(round($hh) + ($mm + ($ss / $unitm)) / $unitm, 2)); case 3: return $minus . number_format(round($hh) + ($mm + ($ss / $unitm)) / $unitm, 2); } } function test(){ echo formatHMS(10021, false, 0) . PHP_EOL; echo formatHMS(10021, false, 1) . PHP_EOL; echo formatHMS(10021, false, 2) . PHP_EOL; echo formatHMS(10021, false, 3) . PHP_EOL; } for($i = 0; $i < 1000; $i++){ test(); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 7, Position 2 = 2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 2
2 jumps found. (Code = 44) Position 1 = 7, Position 2 = 2
Branch analysis from position: 7
Branch analysis from position: 2
filename:       /in/QtACX
function name:  (null)
number of ops:  8
compiled vars:  !0 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   ASSIGN                                                   !0, 0
          1      > JMP                                                      ->5
   63     2    >   INIT_FCALL                                               'test'
          3        DO_FCALL                                      0          
   62     4        PRE_INC                                                  !0
          5    >   IS_SMALLER                                               !0, 1000
          6      > JMPNZ                                                    ~4, ->2
   64     7    > > RETURN                                                   1

Function formathms:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 9
Branch analysis from position: 6
2 jumps found. (Code = 46) Position 1 = 25, Position 2 = 27
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 32
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 32
Branch analysis from position: 30
2 jumps found. (Code = 47) Position 1 = 34, Position 2 = 36
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 97
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 62
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 62
2 jumps found. (Code = 43) Position 1 = 64, Position 2 = 79
Branch analysis from position: 64
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 79
2 jumps found. (Code = 43) Position 1 = 81, Position 2 = 91
Branch analysis from position: 81
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 91
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 97
2 jumps found. (Code = 44) Position 1 = 99, Position 2 = 104
Branch analysis from position: 99
2 jumps found. (Code = 44) Position 1 = 101, Position 2 = 150
Branch analysis from position: 101
2 jumps found. (Code = 44) Position 1 = 103, Position 2 = 168
Branch analysis from position: 103
1 jumps found. (Code = 42) Position 1 = 181
Branch analysis from position: 181
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 168
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 150
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 104
2 jumps found. (Code = 43) Position 1 = 105, Position 2 = 132
Branch analysis from position: 105
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 132
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
Branch analysis from position: 32
Branch analysis from position: 32
Branch analysis from position: 27
Branch analysis from position: 9
filename:       /in/QtACX
function name:  formatHMS
number of ops:  182
compiled vars:  !0 = $inputval, !1 = $full, !2 = $timeFormat, !3 = $minus, !4 = $unith, !5 = $unitm, !6 = $hh, !7 = $ss_remaining, !8 = $mm, !9 = $ss
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <false>
          2        RECV_INIT                                        !2      ''
    6     3        ASSIGN                                                   !3, ''
    7     4        IS_SMALLER                                               !0, 0
          5      > JMPZ                                                     ~11, ->9
    8     6    >   ASSIGN                                                   !3, '-+'
    9     7        MUL                                              ~13     !0, -1
          8        ASSIGN                                                   !0, ~13
   12     9    >   ASSIGN                                                   !4, 3600
   13    10        ASSIGN                                                   !5, 60
   15    11        DIV                                              ~17     !0, !4
         12        CAST                                          4  ~18     ~17
         13        ASSIGN                                                   !6, ~18
   16    14        MUL                                              ~20     !6, 3600
         15        SUB                                              ~21     !0, ~20
         16        ASSIGN                                                   !7, ~21
   18    17        DIV                                              ~23     !7, !5
         18        CAST                                          4  ~24     ~23
         19        ASSIGN                                                   !8, ~24
   19    20        MUL                                              ~26     !8, 60
         21        SUB                                              ~27     !7, ~26
         22        ASSIGN                                                   !9, ~27
   21    23        BOOL_NOT                                         ~29     !1
         24      > JMPZ_EX                                          ~29     ~29, ->27
         25    >   IS_SMALLER                                       ~30     30, !9
         26        BOOL                                             ~29     ~30
         27    > > JMPZ                                                     ~29, ->32
   22    28    >   IS_IDENTICAL                                             !8, 60
         29      > JMPZ                                                     ~31, ->32
   23    30    >   PRE_INC                                                  !6
   24    31        ASSIGN                                                   !8, 0
   28    32    >   IS_EQUAL                                         ~34     !2, ''
         33      > JMPNZ_EX                                         ~34     ~34, ->36
         34    >   IS_EQUAL                                         ~35     !2, 0
         35        BOOL                                             ~34     ~35
         36    > > JMPZ                                                     ~34, ->97
   29    37    > > JMPZ                                                     !1, ->62
   30    38    >   INIT_FCALL                                               'round'
         39        SEND_VAR                                                 !6
         40        DO_ICALL                                         $36     
         41        CONCAT                                           ~37     !3, $36
         42        CONCAT                                           ~38     ~37, 'h+'
         43        INIT_FCALL                                               'sprintf'
         44        SEND_VAL                                                 '%2502d'
         45        INIT_FCALL                                               'round'
         46        SEND_VAR                                                 !8
         47        DO_ICALL                                         $39     
         48        SEND_VAR                                                 $39
         49        DO_ICALL                                         $40     
         50        CONCAT                                           ~41     ~38, $40
         51        CONCAT                                           ~42     ~41, 'm+'
         52        INIT_FCALL                                               'sprintf'
         53        SEND_VAL                                                 '%2502d'
         54        INIT_FCALL                                               'round'
         55        SEND_VAR                                                 !9
         56        DO_ICALL                                         $43     
         57        SEND_VAR                                                 $43
         58        DO_ICALL                                         $44     
         59        CONCAT                                           ~45     ~42, $44
         60        CONCAT                                           ~46     ~45, 's'
         61      > RETURN                                                   ~46
   33    62    >   IS_SMALLER                                               0, !6
         63      > JMPZ                                                     ~47, ->79
   34    64    >   INIT_FCALL                                               'round'
         65        SEND_VAR                                                 !6
         66        DO_ICALL                                         $48     
         67        CONCAT                                           ~49     !3, $48
         68        CONCAT                                           ~50     ~49, 'h+'
         69        INIT_FCALL                                               'sprintf'
         70        SEND_VAL                                                 '%2502d'
         71        INIT_FCALL                                               'round'
         72        SEND_VAR                                                 !8
         73        DO_ICALL                                         $51     
         74        SEND_VAR                                                 $51
         75        DO_ICALL                                         $52     
         76        CONCAT                                           ~53     ~50, $52
         77        CONCAT                                           ~54     ~53, 'm'
         78      > RETURN                                                   ~54
   36    79    >   IS_SMALLER                                               0, !8
         80      > JMPZ                                                     ~55, ->91
   37    81    >   INIT_FCALL                                               'sprintf'
         82        SEND_VAL                                                 '%2502d'
         83        INIT_FCALL                                               'round'
         84        SEND_VAR                                                 !8
         85        DO_ICALL                                         $56     
         86        SEND_VAR                                                 $56
         87        DO_ICALL                                         $57     
         88        CONCAT                                           ~58     !3, $57
         89        CONCAT                                           ~59     ~58, 'm'
         90      > RETURN                                                   ~59
   39    91    >   INIT_FCALL                                               'round'
         92        SEND_VAR                                                 !9
         93        DO_ICALL                                         $60     
         94        CONCAT                                           ~61     !3, $60
         95        CONCAT                                           ~62     ~61, 's'
         96      > RETURN                                                   ~62
   42    97    >   IS_EQUAL                                                 !2, 1
         98      > JMPNZ                                                    ~63, ->104
   48    99    >   IS_EQUAL                                                 !2, 2
        100      > JMPNZ                                                    ~63, ->150
   50   101    >   IS_EQUAL                                                 !2, 3
        102      > JMPNZ                                                    ~63, ->168
        103    > > JMP                                                      ->181
   43   104    > > JMPZ                                                     !1, ->132
   44   105    >   INIT_FCALL                                               'sprintf'
        106        SEND_VAL                                                 '%2502d'
        107        INIT_FCALL                                               'round'
        108        SEND_VAR                                                 !6
        109        DO_ICALL                                         $64     
        110        SEND_VAR                                                 $64
        111        DO_ICALL                                         $65     
        112        CONCAT                                           ~66     !3, $65
        113        CONCAT                                           ~67     ~66, '%3A'
        114        INIT_FCALL                                               'sprintf'
        115        SEND_VAL                                                 '%2502d'
   45   116        INIT_FCALL                                               'round'
        117        SEND_VAR                                                 !8
        118        DO_ICALL                                         $68     
        119        SEND_VAR                                                 $68
        120        DO_ICALL                                         $69     
        121        CONCAT                                           ~70     ~67, $69
        122        CONCAT                                           ~71     ~70, '%3A'
        123        INIT_FCALL                                               'sprintf'
        124        SEND_VAL                                                 '%2502d'
        125        INIT_FCALL                                               'round'
        126        SEND_VAR                                                 !9
        127        DO_ICALL                                         $72     
        128        SEND_VAR                                                 $72
        129        DO_ICALL                                         $73     
        130        CONCAT                                           ~74     ~71, $73
        131      > RETURN                                                   ~74
   47   132    >   INIT_FCALL                                               'sprintf'
        133        SEND_VAL                                                 '%2502d'
        134        INIT_FCALL                                               'round'
        135        SEND_VAR                                                 !6
        136        DO_ICALL                                         $75     
        137        SEND_VAR                                                 $75
        138        DO_ICALL                                         $76     
        139        CONCAT                                           ~77     !3, $76
        140        CONCAT                                           ~78     ~77, '%3A'
        141        INIT_FCALL                                               'sprintf'
        142        SEND_VAL                                                 '%2502d'
        143        INIT_FCALL                                               'round'
        144        SEND_VAR                                                 !8
        145        DO_ICALL                                         $79     
        146        SEND_VAR                                                 $79
        147        DO_ICALL                                         $80     
        148        CONCAT                                           ~81     ~78, $80
        149      > RETURN                                                   ~81
   49   150    >   INIT_FCALL                                               'str_replace'
        151        SEND_VAL                                                 '.'
        152        SEND_VAL                                                 '%2C'
        153        INIT_FCALL                                               'number_format'
        154        INIT_FCALL                                               'round'
        155        SEND_VAR                                                 !6
        156        DO_ICALL                                         $82     
        157        DIV                                              ~83     !9, !5
        158        ADD                                              ~84     !8, ~83
        159        DIV                                              ~85     ~84, !5
        160        ADD                                              ~86     $82, ~85
        161        SEND_VAL                                                 ~86
        162        SEND_VAL                                                 2
        163        DO_ICALL                                         $87     
        164        SEND_VAR                                                 $87
        165        DO_ICALL                                         $88     
        166        CONCAT                                           ~89     !3, $88
        167      > RETURN                                                   ~89
   51   168    >   INIT_FCALL                                               'number_format'
        169        INIT_FCALL                                               'round'
        170        SEND_VAR                                                 !6
        171        DO_ICALL                                         $90     
        172        DIV                                              ~91     !9, !5
        173        ADD                                              ~92     !8, ~91
        174        DIV                                              ~93     ~92, !5
        175        ADD                                              ~94     $90, ~93
        176        SEND_VAL                                                 ~94
        177        SEND_VAL                                                 2
        178        DO_ICALL                                         $95     
        179        CONCAT                                           ~96     !3, $95
        180      > RETURN                                                   ~96
   53   181    > > RETURN                                                   null

End of function formathms

Function test:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QtACX
function name:  test
number of ops:  29
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   INIT_FCALL                                               'formathms'
          1        SEND_VAL                                                 10021
          2        SEND_VAL                                                 <false>
          3        SEND_VAL                                                 0
          4        DO_FCALL                                      0  $0      
          5        CONCAT                                           ~1      $0, '%0A'
          6        ECHO                                                     ~1
   57     7        INIT_FCALL                                               'formathms'
          8        SEND_VAL                                                 10021
          9        SEND_VAL                                                 <false>
         10        SEND_VAL                                                 1
         11        DO_FCALL                                      0  $2      
         12        CONCAT                                           ~3      $2, '%0A'
         13        ECHO                                                     ~3
   58    14        INIT_FCALL                                               'formathms'
         15        SEND_VAL                                                 10021
         16        SEND_VAL                                                 <false>
         17        SEND_VAL                                                 2
         18        DO_FCALL                                      0  $4      
         19        CONCAT                                           ~5      $4, '%0A'
         20        ECHO                                                     ~5
   59    21        INIT_FCALL                                               'formathms'
         22        SEND_VAL                                                 10021
         23        SEND_VAL                                                 <false>
         24        SEND_VAL                                                 3
         25        DO_FCALL                                      0  $6      
         26        CONCAT                                           ~7      $6, '%0A'
         27        ECHO                                                     ~7
   60    28      > RETURN                                                   null

End of function test

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.25 ms | 1419 KiB | 26 Q