3v4l.org

run code in 300+ PHP versions simultaneously
<?php function timeSince($time, $from = null) { if ($from == null) { $from = time(); } $time = $from - $time; $chunks = array( array(60 * 60 * 24 * 365 , 'year'), array(60 * 60 * 24 * 30 , 'month'), array(60 * 60 * 24 , 'day'), array(60 * 60 , 'hour'), array(60 , 'minute'), array(1 , 'second') ); for ($i = 0, $j = count($chunks); $i < $j; $i++) { $seconds = $chunks[$i][0]; $name = $chunks[$i][1]; if (($count = floor($time / $seconds)) != 0) { break; } } $print = ($count == 1) ? '1 '.$name : "$count {$name}s"; return $print; } $dt = strtotime('2014-1-11'); echo "since ",timeSince($dt);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JYUeK
function name:  (null)
number of ops:  10
compiled vars:  !0 = $dt
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   INIT_FCALL                                               'strtotime'
          1        SEND_VAL                                                 '2014-1-11'
          2        DO_ICALL                                         $1      
          3        ASSIGN                                                   !0, $1
   33     4        ECHO                                                     'since+'
          5        INIT_FCALL                                               'timesince'
          6        SEND_VAR                                                 !0
          7        DO_FCALL                                      0  $3      
          8        ECHO                                                     $3
          9      > RETURN                                                   1

Function timesince:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 14
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 36
Branch analysis from position: 33
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: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 28
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 14
Branch analysis from position: 31
Branch analysis from position: 14
Branch analysis from position: 7
filename:       /in/JYUeK
function name:  timeSince
number of ops:  44
compiled vars:  !0 = $time, !1 = $from, !2 = $chunks, !3 = $i, !4 = $j, !5 = $seconds, !6 = $name, !7 = $count, !8 = $print
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
    5     2        IS_EQUAL                                                 !1, null
          3      > JMPZ                                                     ~9, ->7
    6     4    >   INIT_FCALL                                               'time'
          5        DO_ICALL                                         $10     
          6        ASSIGN                                                   !1, $10
    8     7    >   SUB                                              ~12     !1, !0
          8        ASSIGN                                                   !0, ~12
   10     9        ASSIGN                                                   !2, <array>
   19    10        ASSIGN                                                   !3, 0
         11        COUNT                                            ~16     !2
         12        ASSIGN                                                   !4, ~16
         13      > JMP                                                      ->29
   20    14    >   FETCH_DIM_R                                      ~18     !2, !3
         15        FETCH_DIM_R                                      ~19     ~18, 0
         16        ASSIGN                                                   !5, ~19
   21    17        FETCH_DIM_R                                      ~21     !2, !3
         18        FETCH_DIM_R                                      ~22     ~21, 1
         19        ASSIGN                                                   !6, ~22
   22    20        INIT_FCALL                                               'floor'
         21        DIV                                              ~24     !0, !5
         22        SEND_VAL                                                 ~24
         23        DO_ICALL                                         $25     
         24        ASSIGN                                           ~26     !7, $25
         25        IS_NOT_EQUAL                                             ~26, 0
         26      > JMPZ                                                     ~27, ->28
   23    27    > > JMP                                                      ->31
   19    28    >   PRE_INC                                                  !3
         29    >   IS_SMALLER                                               !3, !4
         30      > JMPNZ                                                    ~29, ->14
   27    31    >   IS_EQUAL                                                 !7, 1
         32      > JMPZ                                                     ~30, ->36
         33    >   CONCAT                                           ~31     '1+', !6
         34        QM_ASSIGN                                        ~32     ~31
         35      > JMP                                                      ->41
         36    >   ROPE_INIT                                     4  ~34     !7
         37        ROPE_ADD                                      1  ~34     ~34, '+'
         38        ROPE_ADD                                      2  ~34     ~34, !6
         39        ROPE_END                                      3  ~33     ~34, 's'
         40        QM_ASSIGN                                        ~32     ~33
         41    >   ASSIGN                                                   !8, ~32
   28    42      > RETURN                                                   !8
   29    43*     > RETURN                                                   null

End of function timesince

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.71 ms | 1403 KiB | 20 Q