3v4l.org

run code in 300+ PHP versions simultaneously
<?php function ago($when) { $diff = date("U") - $when; // Days $day = floor($diff / 86400); $diff = $diff - ($day * 86400); // Hours $hrs = floor($diff / 3600); $diff = $diff - ($hrs * 3600); // Mins $min = floor($diff / 60); $diff = $diff - ($min * 60); // Secs $sec = $diff; // Return how long ago this was. eg: 3d 17h 4m 18s ago // Skips left fields if they aren't necessary, eg. 16h 0m 27s ago / 10m 7s ago $str = sprintf("%s%s%s%s", $day != 0 ? $day."d " : "", ($day != 0 || $hrs != 0) ? $hrs."h " : "", ($day != 0 || $hrs != 0 || $min != 0) ? $min."m " : "", $sec."s ago" ); return $str; } echo ago(3600);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vmMnM
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   INIT_FCALL                                               'ago'
          1        SEND_VAL                                                 3600
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
          4      > RETURN                                                   1

Function ago:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 38
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
2 jumps found. (Code = 47) Position 1 = 42, Position 2 = 44
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 48
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
2 jumps found. (Code = 47) Position 1 = 52, Position 2 = 54
Branch analysis from position: 52
2 jumps found. (Code = 47) Position 1 = 55, Position 2 = 57
Branch analysis from position: 55
2 jumps found. (Code = 43) Position 1 = 58, Position 2 = 61
Branch analysis from position: 58
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: 61
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 57
Branch analysis from position: 54
Branch analysis from position: 48
2 jumps found. (Code = 47) Position 1 = 52, Position 2 = 54
Branch analysis from position: 52
Branch analysis from position: 54
Branch analysis from position: 44
Branch analysis from position: 38
2 jumps found. (Code = 47) Position 1 = 42, Position 2 = 44
Branch analysis from position: 42
Branch analysis from position: 44
filename:       /in/vmMnM
function name:  ago
number of ops:  69
compiled vars:  !0 = $when, !1 = $diff, !2 = $day, !3 = $hrs, !4 = $min, !5 = $sec, !6 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'date'
          2        SEND_VAL                                                 'U'
          3        DO_ICALL                                         $7      
          4        SUB                                              ~8      $7, !0
          5        ASSIGN                                                   !1, ~8
    7     6        INIT_FCALL                                               'floor'
          7        DIV                                              ~10     !1, 86400
          8        SEND_VAL                                                 ~10
          9        DO_ICALL                                         $11     
         10        ASSIGN                                                   !2, $11
    8    11        MUL                                              ~13     !2, 86400
         12        SUB                                              ~14     !1, ~13
         13        ASSIGN                                                   !1, ~14
   11    14        INIT_FCALL                                               'floor'
         15        DIV                                              ~16     !1, 3600
         16        SEND_VAL                                                 ~16
         17        DO_ICALL                                         $17     
         18        ASSIGN                                                   !3, $17
   12    19        MUL                                              ~19     !3, 3600
         20        SUB                                              ~20     !1, ~19
         21        ASSIGN                                                   !1, ~20
   15    22        INIT_FCALL                                               'floor'
         23        DIV                                              ~22     !1, 60
         24        SEND_VAL                                                 ~22
         25        DO_ICALL                                         $23     
         26        ASSIGN                                                   !4, $23
   16    27        MUL                                              ~25     !4, 60
         28        SUB                                              ~26     !1, ~25
         29        ASSIGN                                                   !1, ~26
   19    30        ASSIGN                                                   !5, !1
   23    31        INIT_FCALL                                               'sprintf'
         32        SEND_VAL                                                 '%25s%25s%25s%25s'
   24    33        IS_NOT_EQUAL                                             !2, 0
         34      > JMPZ                                                     ~29, ->38
         35    >   CONCAT                                           ~30     !2, 'd+'
         36        QM_ASSIGN                                        ~31     ~30
         37      > JMP                                                      ->39
         38    >   QM_ASSIGN                                        ~31     ''
         39    >   SEND_VAL                                                 ~31
   25    40        IS_NOT_EQUAL                                     ~32     !2, 0
         41      > JMPNZ_EX                                         ~32     ~32, ->44
         42    >   IS_NOT_EQUAL                                     ~33     !3, 0
         43        BOOL                                             ~32     ~33
         44    > > JMPZ                                                     ~32, ->48
         45    >   CONCAT                                           ~34     !3, 'h+'
         46        QM_ASSIGN                                        ~35     ~34
         47      > JMP                                                      ->49
         48    >   QM_ASSIGN                                        ~35     ''
         49    >   SEND_VAL                                                 ~35
   26    50        IS_NOT_EQUAL                                     ~36     !2, 0
         51      > JMPNZ_EX                                         ~36     ~36, ->54
         52    >   IS_NOT_EQUAL                                     ~37     !3, 0
         53        BOOL                                             ~36     ~37
         54    > > JMPNZ_EX                                         ~36     ~36, ->57
         55    >   IS_NOT_EQUAL                                     ~38     !4, 0
         56        BOOL                                             ~36     ~38
         57    > > JMPZ                                                     ~36, ->61
         58    >   CONCAT                                           ~39     !4, 'm+'
         59        QM_ASSIGN                                        ~40     ~39
         60      > JMP                                                      ->62
         61    >   QM_ASSIGN                                        ~40     ''
         62    >   SEND_VAL                                                 ~40
   27    63        CONCAT                                           ~41     !5, 's+ago'
         64        SEND_VAL                                                 ~41
         65        DO_ICALL                                         $42     
   23    66        ASSIGN                                                   !6, $42
   30    67      > RETURN                                                   !6
   31    68*     > RETURN                                                   null

End of function ago

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.57 ms | 1407 KiB | 20 Q