3v4l.org

run code in 300+ PHP versions simultaneously
<?php $timestamp = time(); echo $timestamp; echo "\n-----"; sleep(1); echo time_stamp($timestamp); function time_stamp($timestamp){ //type cast, current time, difference in timestamps $timestamp = (int) $timestamp; $current_time = time(); $diff = $current_time - $timestamp; //intervals in seconds $intervals = array ( 'year' => 31556926, 'month' => 2629744, 'week' => 604800, 'day' => 86400, 'hour' => 3600, 'minute'=> 60 ); //now we just find the difference if ($diff == 0) { return 'just now'; } if ($diff < 60) { return $diff == 1 ? $diff . ' second ago' : $diff . ' seconds ago'; } if ($diff >= 60 && $diff < $intervals['hour']) { $diff = floor($diff/$intervals['minute']); return $diff == 1 ? $diff . ' minute ago' : $diff . ' minutes ago'; } if ($diff >= $intervals['hour'] && $diff < $intervals['day']) { $diff = floor($diff/$intervals['hour']); return $diff == 1 ? $diff . ' hour ago' : $diff . ' hours ago'; } if ($diff >= $intervals['day'] && $diff < $intervals['week']) { $diff = floor($diff/$intervals['day']); return $diff == 1 ? $diff . ' day ago' : $diff . ' days ago'; } if ($diff >= $intervals['week'] && $diff < $intervals['month']) { $diff = floor($diff/$intervals['week']); return $diff == 1 ? $diff . ' week ago' : $diff . ' weeks ago'; } if ($diff >= $intervals['month'] && $diff < $intervals['year']) { $diff = floor($diff/$intervals['month']); return $diff == 1 ? $diff . ' month ago' : $diff . ' months ago'; } if ($diff >= $intervals['year']) { $diff = floor($diff/$intervals['year']); return $diff == 1 ? $diff . ' year ago' : $diff . ' years ago'; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ethpk
function name:  (null)
number of ops:  13
compiled vars:  !0 = $timestamp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   INIT_FCALL                                               'time'
          1        DO_ICALL                                         $1      
          2        ASSIGN                                                   !0, $1
    3     3        ECHO                                                     !0
    4     4        ECHO                                                     '%0A-----'
    5     5        INIT_FCALL                                               'sleep'
          6        SEND_VAL                                                 1
          7        DO_ICALL                                                 
    6     8        INIT_FCALL_BY_NAME                                       'time_stamp'
          9        SEND_VAR_EX                                              !0
         10        DO_FCALL                                      0  $4      
         11        ECHO                                                     $4
   64    12      > RETURN                                                   1

Function time_stamp:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 12
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 22
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 19
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
2 jumps found. (Code = 46) Position 1 = 24, Position 2 = 27
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 42
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 39
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
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: 42
2 jumps found. (Code = 46) Position 1 = 45, Position 2 = 48
Branch analysis from position: 45
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 63
Branch analysis from position: 49
2 jumps found. (Code = 43) Position 1 = 57, Position 2 = 60
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 62
Branch analysis from position: 62
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 60
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 63
2 jumps found. (Code = 46) Position 1 = 66, Position 2 = 69
Branch analysis from position: 66
2 jumps found. (Code = 43) Position 1 = 70, Position 2 = 84
Branch analysis from position: 70
2 jumps found. (Code = 43) Position 1 = 78, Position 2 = 81
Branch analysis from position: 78
1 jumps found. (Code = 42) Position 1 = 83
Branch analysis from position: 83
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 81
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 84
2 jumps found. (Code = 46) Position 1 = 87, Position 2 = 90
Branch analysis from position: 87
2 jumps found. (Code = 43) Position 1 = 91, Position 2 = 105
Branch analysis from position: 91
2 jumps found. (Code = 43) Position 1 = 99, Position 2 = 102
Branch analysis from position: 99
1 jumps found. (Code = 42) Position 1 = 104
Branch analysis from position: 104
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 102
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 105
2 jumps found. (Code = 46) Position 1 = 108, Position 2 = 111
Branch analysis from position: 108
2 jumps found. (Code = 43) Position 1 = 112, Position 2 = 126
Branch analysis from position: 112
2 jumps found. (Code = 43) Position 1 = 120, Position 2 = 123
Branch analysis from position: 120
1 jumps found. (Code = 42) Position 1 = 125
Branch analysis from position: 125
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 123
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 126
2 jumps found. (Code = 43) Position 1 = 129, Position 2 = 143
Branch analysis from position: 129
2 jumps found. (Code = 43) Position 1 = 137, Position 2 = 140
Branch analysis from position: 137
1 jumps found. (Code = 42) Position 1 = 142
Branch analysis from position: 142
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 140
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 143
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 111
Branch analysis from position: 90
Branch analysis from position: 69
Branch analysis from position: 48
Branch analysis from position: 27
filename:       /in/ethpk
function name:  time_stamp
number of ops:  144
compiled vars:  !0 = $timestamp, !1 = $current_time, !2 = $diff, !3 = $intervals
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    9     1        CAST                                          4  ~4      !0
          2        ASSIGN                                                   !0, ~4
   10     3        INIT_FCALL                                               'time'
          4        DO_ICALL                                         $6      
          5        ASSIGN                                                   !1, $6
   11     6        SUB                                              ~8      !1, !0
          7        ASSIGN                                                   !2, ~8
   14     8        ASSIGN                                                   !3, <array>
   19     9        IS_EQUAL                                                 !2, 0
         10      > JMPZ                                                     ~11, ->12
   21    11    > > RETURN                                                   'just+now'
   24    12    >   IS_SMALLER                                               !2, 60
         13      > JMPZ                                                     ~12, ->22
   26    14    >   IS_EQUAL                                                 !2, 1
         15      > JMPZ                                                     ~13, ->19
         16    >   CONCAT                                           ~14     !2, '+second+ago'
         17        QM_ASSIGN                                        ~15     ~14
         18      > JMP                                                      ->21
         19    >   CONCAT                                           ~16     !2, '+seconds+ago'
         20        QM_ASSIGN                                        ~15     ~16
         21    > > RETURN                                                   ~15
   29    22    >   IS_SMALLER_OR_EQUAL                              ~17     60, !2
         23      > JMPZ_EX                                          ~17     ~17, ->27
         24    >   FETCH_DIM_R                                      ~18     !3, 'hour'
         25        IS_SMALLER                                       ~19     !2, ~18
         26        BOOL                                             ~17     ~19
         27    > > JMPZ                                                     ~17, ->42
   31    28    >   INIT_FCALL                                               'floor'
         29        FETCH_DIM_R                                      ~20     !3, 'minute'
         30        DIV                                              ~21     !2, ~20
         31        SEND_VAL                                                 ~21
         32        DO_ICALL                                         $22     
         33        ASSIGN                                                   !2, $22
   32    34        IS_EQUAL                                                 !2, 1
         35      > JMPZ                                                     ~24, ->39
         36    >   CONCAT                                           ~25     !2, '+minute+ago'
         37        QM_ASSIGN                                        ~26     ~25
         38      > JMP                                                      ->41
         39    >   CONCAT                                           ~27     !2, '+minutes+ago'
         40        QM_ASSIGN                                        ~26     ~27
         41    > > RETURN                                                   ~26
   35    42    >   FETCH_DIM_R                                      ~28     !3, 'hour'
         43        IS_SMALLER_OR_EQUAL                              ~29     ~28, !2
         44      > JMPZ_EX                                          ~29     ~29, ->48
         45    >   FETCH_DIM_R                                      ~30     !3, 'day'
         46        IS_SMALLER                                       ~31     !2, ~30
         47        BOOL                                             ~29     ~31
         48    > > JMPZ                                                     ~29, ->63
   37    49    >   INIT_FCALL                                               'floor'
         50        FETCH_DIM_R                                      ~32     !3, 'hour'
         51        DIV                                              ~33     !2, ~32
         52        SEND_VAL                                                 ~33
         53        DO_ICALL                                         $34     
         54        ASSIGN                                                   !2, $34
   38    55        IS_EQUAL                                                 !2, 1
         56      > JMPZ                                                     ~36, ->60
         57    >   CONCAT                                           ~37     !2, '+hour+ago'
         58        QM_ASSIGN                                        ~38     ~37
         59      > JMP                                                      ->62
         60    >   CONCAT                                           ~39     !2, '+hours+ago'
         61        QM_ASSIGN                                        ~38     ~39
         62    > > RETURN                                                   ~38
   41    63    >   FETCH_DIM_R                                      ~40     !3, 'day'
         64        IS_SMALLER_OR_EQUAL                              ~41     ~40, !2
         65      > JMPZ_EX                                          ~41     ~41, ->69
         66    >   FETCH_DIM_R                                      ~42     !3, 'week'
         67        IS_SMALLER                                       ~43     !2, ~42
         68        BOOL                                             ~41     ~43
         69    > > JMPZ                                                     ~41, ->84
   43    70    >   INIT_FCALL                                               'floor'
         71        FETCH_DIM_R                                      ~44     !3, 'day'
         72        DIV                                              ~45     !2, ~44
         73        SEND_VAL                                                 ~45
         74        DO_ICALL                                         $46     
         75        ASSIGN                                                   !2, $46
   44    76        IS_EQUAL                                                 !2, 1
         77      > JMPZ                                                     ~48, ->81
         78    >   CONCAT                                           ~49     !2, '+day+ago'
         79        QM_ASSIGN                                        ~50     ~49
         80      > JMP                                                      ->83
         81    >   CONCAT                                           ~51     !2, '+days+ago'
         82        QM_ASSIGN                                        ~50     ~51
         83    > > RETURN                                                   ~50
   47    84    >   FETCH_DIM_R                                      ~52     !3, 'week'
         85        IS_SMALLER_OR_EQUAL                              ~53     ~52, !2
         86      > JMPZ_EX                                          ~53     ~53, ->90
         87    >   FETCH_DIM_R                                      ~54     !3, 'month'
         88        IS_SMALLER                                       ~55     !2, ~54
         89        BOOL                                             ~53     ~55
         90    > > JMPZ                                                     ~53, ->105
   49    91    >   INIT_FCALL                                               'floor'
         92        FETCH_DIM_R                                      ~56     !3, 'week'
         93        DIV                                              ~57     !2, ~56
         94        SEND_VAL                                                 ~57
         95        DO_ICALL                                         $58     
         96        ASSIGN                                                   !2, $58
   50    97        IS_EQUAL                                                 !2, 1
         98      > JMPZ                                                     ~60, ->102
         99    >   CONCAT                                           ~61     !2, '+week+ago'
        100        QM_ASSIGN                                        ~62     ~61
        101      > JMP                                                      ->104
        102    >   CONCAT                                           ~63     !2, '+weeks+ago'
        103        QM_ASSIGN                                        ~62     ~63
        104    > > RETURN                                                   ~62
   53   105    >   FETCH_DIM_R                                      ~64     !3, 'month'
        106        IS_SMALLER_OR_EQUAL                              ~65     ~64, !2
        107      > JMPZ_EX                                          ~65     ~65, ->111
        108    >   FETCH_DIM_R                                      ~66     !3, 'year'
        109        IS_SMALLER                                       ~67     !2, ~66
        110        BOOL                                             ~65     ~67
        111    > > JMPZ                                                     ~65, ->126
   55   112    >   INIT_FCALL                                               'floor'
        113        FETCH_DIM_R                                      ~68     !3, 'month'
        114        DIV                                              ~69     !2, ~68
        115        SEND_VAL                                                 ~69
        116        DO_ICALL                                         $70     
        117        ASSIGN                                                   !2, $70
   56   118        IS_EQUAL                                                 !2, 1
        119      > JMPZ                                                     ~72, ->123
        120    >   CONCAT                                           ~73     !2, '+month+ago'
        121        QM_ASSIGN                                        ~74     ~73
        122      > JMP                                                      ->125
        123    >   CONCAT                                           ~75     !2, '+months+ago'
        124        QM_ASSIGN                                        ~74     ~75
        125    > > RETURN                                                   ~74
   59   126    >   FETCH_DIM_R                                      ~76     !3, 'year'
        127        IS_SMALLER_OR_EQUAL                                      ~76, !2
        128      > JMPZ                                                     ~77, ->143
   61   129    >   INIT_FCALL                                               'floor'
        130        FETCH_DIM_R                                      ~78     !3, 'year'
        131        DIV                                              ~79     !2, ~78
        132        SEND_VAL                                                 ~79
        133        DO_ICALL                                         $80     
        134        ASSIGN                                                   !2, $80
   62   135        IS_EQUAL                                                 !2, 1
        136      > JMPZ                                                     ~82, ->140
        137    >   CONCAT                                           ~83     !2, '+year+ago'
        138        QM_ASSIGN                                        ~84     ~83
        139      > JMP                                                      ->142
        140    >   CONCAT                                           ~85     !2, '+years+ago'
        141        QM_ASSIGN                                        ~84     ~85
        142    > > RETURN                                                   ~84
   64   143    > > RETURN                                                   null

End of function time_stamp

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.87 ms | 1412 KiB | 19 Q