3v4l.org

run code in 300+ PHP versions simultaneously
<?php function humanTime($hour, $min) { $times = [ 0 => '%s o\'clock', 2 => 'couple of mins past %s', 5 => 'five past %s', 8 => 'around ten past %s', 10 => 'ten past %s', 15 => 'quarter past %s', 20 => 'twenty past %s', 25 => 'twenty five past %s', 27 => 'around half past %s', 30 => 'half past %s', 33 => 'around thirty five past %s', 35 => 'thirty five past %s', 40 => 'twenty to %s', 43 => 'around quarter to %s', 45 => 'quarter to %s', 47 => 'about ten to %s', 50 => 'ten to %s', 53 => 'about five to %s', 55 => 'five to %s' ]; $hourWord = [ 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve' ]; $hour = (int) $hour; $min = (int) $min; $closest = null; foreach ($times as $key => $item) if ($closest === null || abs($min - $closest) > abs($key - $min)) $closest = $key; if ($hour === 0) $hour = 12; if ($min > 40) $hour = $hour === 12 ? 1 : $hour + 1; return sprintf($times[$closest], $hourWord[(int) $hour - 1]); } // test foreach (range(0, 11) as $hour) { // $hour = str_pad($hour, 2, "0", STR_PAD_LEFT); foreach(range(0, 59) as $min) { // $min = str_pad($min, 2, "0", STR_PAD_LEFT); // echo 'Time: ' . $hour .':' . $min.PHP_EOL; echo 'It\'s ' . humanTime($hour, $min).PHP_EOL; } }

Abusive script

This script was stopped while abusing our resources

Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 41
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 41
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 39
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 39
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 39
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
filename:       /in/7rV89
function name:  (null)
number of ops:  43
compiled vars:  !0 = $hour, !1 = $min
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   INIT_FCALL                                               'range'
          1        SEND_VAL                                                 0
          2        SEND_VAL                                                 11
          3        DO_ICALL                                         $2      
          4      > FE_RESET_R                                       $3      $2, ->41
          5    > > FE_FETCH_R                                               $3, !0, ->41
   58     6    >   INIT_FCALL                                               'str_pad'
          7        SEND_VAR                                                 !0
          8        SEND_VAL                                                 2
          9        SEND_VAL                                                 '0'
         10        SEND_VAL                                                 0
         11        DO_ICALL                                         $4      
         12        ASSIGN                                                   !0, $4
   60    13        INIT_FCALL                                               'range'
         14        SEND_VAL                                                 0
         15        SEND_VAL                                                 59
         16        DO_ICALL                                         $6      
         17      > FE_RESET_R                                       $7      $6, ->39
         18    > > FE_FETCH_R                                               $7, !1, ->39
   62    19    >   INIT_FCALL                                               'str_pad'
         20        SEND_VAR                                                 !1
         21        SEND_VAL                                                 2
         22        SEND_VAL                                                 '0'
         23        SEND_VAL                                                 0
         24        DO_ICALL                                         $8      
         25        ASSIGN                                                   !1, $8
   65    26        CONCAT                                           ~10     'Time%3A+', !0
         27        CONCAT                                           ~11     ~10, '%3A'
         28        CONCAT                                           ~12     ~11, !1
         29        CONCAT                                           ~13     ~12, '%0A'
         30        ECHO                                                     ~13
   66    31        INIT_FCALL                                               'humantime'
         32        SEND_VAR                                                 !0
         33        SEND_VAR                                                 !1
         34        DO_FCALL                                      0  $14     
         35        CONCAT                                           ~15     'It%27s+', $14
         36        CONCAT                                           ~16     ~15, '%0A'
         37        ECHO                                                     ~16
   60    38      > JMP                                                      ->18
         39    >   FE_FREE                                                  $7
   56    40      > JMP                                                      ->5
         41    >   FE_FREE                                                  $3
   68    42      > RETURN                                                   1

Function humantime:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 27
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 27
Branch analysis from position: 11
2 jumps found. (Code = 47) Position 1 = 14, Position 2 = 24
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 26
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 26
Branch analysis from position: 24
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 31
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 40
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
Branch analysis from position: 31
Branch analysis from position: 27
filename:       /in/7rV89
function name:  humanTime
number of ops:  50
compiled vars:  !0 = $hour, !1 = $min, !2 = $times, !3 = $hourWord, !4 = $closest, !5 = $item, !6 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        ASSIGN                                                   !2, <array>
   26     3        ASSIGN                                                   !3, <array>
   41     4        CAST                                          4  ~9      !0
          5        ASSIGN                                                   !0, ~9
   42     6        CAST                                          4  ~11     !1
          7        ASSIGN                                                   !1, ~11
   44     8        ASSIGN                                                   !4, null
   45     9      > FE_RESET_R                                       $14     !2, ->27
         10    > > FE_FETCH_R                                       ~15     $14, !5, ->27
         11    >   ASSIGN                                                   !6, ~15
   46    12        TYPE_CHECK                                    2  ~17     !4
         13      > JMPNZ_EX                                         ~17     ~17, ->24
         14    >   INIT_FCALL                                               'abs'
         15        SUB                                              ~18     !1, !4
         16        SEND_VAL                                                 ~18
         17        DO_ICALL                                         $19     
         18        INIT_FCALL                                               'abs'
         19        SUB                                              ~20     !6, !1
         20        SEND_VAL                                                 ~20
         21        DO_ICALL                                         $21     
         22        IS_SMALLER                                       ~22     $21, $19
         23        BOOL                                             ~17     ~22
         24    > > JMPZ                                                     ~17, ->26
         25    >   ASSIGN                                                   !4, !6
   45    26    > > JMP                                                      ->10
         27    >   FE_FREE                                                  $14
   48    28        IS_IDENTICAL                                             !0, 0
         29      > JMPZ                                                     ~24, ->31
         30    >   ASSIGN                                                   !0, 12
   50    31    >   IS_SMALLER                                               40, !1
         32      > JMPZ                                                     ~26, ->40
         33    >   IS_IDENTICAL                                             !0, 12
         34      > JMPZ                                                     ~27, ->37
         35    >   QM_ASSIGN                                        ~28     1
         36      > JMP                                                      ->39
         37    >   ADD                                              ~29     !0, 1
         38        QM_ASSIGN                                        ~28     ~29
         39    >   ASSIGN                                                   !0, ~28
   52    40    >   INIT_FCALL                                               'sprintf'
         41        FETCH_DIM_R                                      ~31     !2, !4
         42        SEND_VAL                                                 ~31
         43        CAST                                          4  ~32     !0
         44        SUB                                              ~33     ~32, 1
         45        FETCH_DIM_R                                      ~34     !3, ~33
         46        SEND_VAL                                                 ~34
         47        DO_ICALL                                         $35     
         48      > RETURN                                                   $35
   53    49*     > RETURN                                                   null

End of function humantime

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.71 ms | 1025 KiB | 18 Q