3v4l.org

run code in 300+ PHP versions simultaneously
<?php function time_elapsed_string($datetime, $full = false) { $now = new DateTime; $ago = new DateTime($datetime); $diff = $now->diff($ago); $diff->w = floor($diff->d / 7); $diff->d -= $diff->w * 7; $string = array( 'h' => 'hour', 'i' => 'minute', 's' => 'second', ); foreach ($string as $k => &$v) { if ($diff->$k) { $v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : ''); } else { unset($string[$k]); } } if (!$full) $string = array_slice($string, 0, 1); return $string ? implode(', ', $string) . ' ago' : 'just now'; } $date = date_parse_from_format('Y-d-m H:i:s', '2014-02-05 5:22:35'); $unixTimestamp = mktime( $date['hour'], $date['minute'], $date['second'], $date['month'], $date['day'], $date['year'] ); echo time_elapsed_string(date('Y-m-d H:i:s',$unixTimestamp), false);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0n3ot
function name:  (null)
number of ops:  30
compiled vars:  !0 = $date, !1 = $unixTimestamp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   INIT_FCALL                                               'date_parse_from_format'
          1        SEND_VAL                                                 'Y-d-m+H%3Ai%3As'
          2        SEND_VAL                                                 '2014-02-05+5%3A22%3A35'
          3        DO_ICALL                                         $2      
          4        ASSIGN                                                   !0, $2
   29     5        INIT_FCALL                                               'mktime'
   30     6        FETCH_DIM_R                                      ~4      !0, 'hour'
          7        SEND_VAL                                                 ~4
          8        FETCH_DIM_R                                      ~5      !0, 'minute'
          9        SEND_VAL                                                 ~5
         10        FETCH_DIM_R                                      ~6      !0, 'second'
         11        SEND_VAL                                                 ~6
   31    12        FETCH_DIM_R                                      ~7      !0, 'month'
         13        SEND_VAL                                                 ~7
         14        FETCH_DIM_R                                      ~8      !0, 'day'
         15        SEND_VAL                                                 ~8
         16        FETCH_DIM_R                                      ~9      !0, 'year'
         17        SEND_VAL                                                 ~9
         18        DO_ICALL                                         $10     
   29    19        ASSIGN                                                   !1, $10
   34    20        INIT_FCALL                                               'time_elapsed_string'
         21        INIT_FCALL                                               'date'
         22        SEND_VAL                                                 'Y-m-d+H%3Ai%3As'
         23        SEND_VAR                                                 !1
         24        DO_ICALL                                         $12     
         25        SEND_VAR                                                 $12
         26        SEND_VAL                                                 <false>
         27        DO_FCALL                                      0  $13     
         28        ECHO                                                     $13
         29      > RETURN                                                   1

Function time_elapsed_string:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 26, Position 2 = 44
Branch analysis from position: 26
2 jumps found. (Code = 126) Position 1 = 27, Position 2 = 44
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 42
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 38
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 53
Branch analysis from position: 47
2 jumps found. (Code = 43) Position 1 = 54, Position 2 = 61
Branch analysis from position: 54
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: 53
Branch analysis from position: 44
filename:       /in/0n3ot
function name:  time_elapsed_string
number of ops:  64
compiled vars:  !0 = $datetime, !1 = $full, !2 = $now, !3 = $ago, !4 = $diff, !5 = $string, !6 = $v, !7 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <false>
    4     2        NEW                                              $8      'DateTime'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !2, $8
    5     5        NEW                                              $11     'DateTime'
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !3, $11
    6     9        INIT_METHOD_CALL                                         !2, 'diff'
         10        SEND_VAR_EX                                              !3
         11        DO_FCALL                                      0  $14     
         12        ASSIGN                                                   !4, $14
    8    13        INIT_FCALL                                               'floor'
         14        FETCH_OBJ_R                                      ~17     !4, 'd'
         15        DIV                                              ~18     ~17, 7
         16        SEND_VAL                                                 ~18
         17        DO_ICALL                                         $19     
         18        ASSIGN_OBJ                                               !4, 'w'
         19        OP_DATA                                                  $19
    9    20        FETCH_OBJ_R                                      ~21     !4, 'w'
         21        MUL                                              ~22     ~21, 7
         22        ASSIGN_OBJ_OP                                 2          !4, 'd'
         23        OP_DATA                                                  ~22
   11    24        ASSIGN                                                   !5, <array>
   16    25      > FE_RESET_RW                                      $24     !5, ->44
         26    > > FE_FETCH_RW                                      ~25     $24, !6, ->44
         27    >   ASSIGN                                                   !7, ~25
   17    28        FETCH_OBJ_R                                      ~27     !4, !7
         29      > JMPZ                                                     ~27, ->42
   18    30    >   FETCH_OBJ_R                                      ~28     !4, !7
         31        CONCAT                                           ~29     ~28, '+'
         32        CONCAT                                           ~30     ~29, !6
         33        FETCH_OBJ_R                                      ~31     !4, !7
         34        IS_SMALLER                                               1, ~31
         35      > JMPZ                                                     ~32, ->38
         36    >   QM_ASSIGN                                        ~33     's'
         37      > JMP                                                      ->39
         38    >   QM_ASSIGN                                        ~33     ''
         39    >   CONCAT                                           ~34     ~30, ~33
         40        ASSIGN                                                   !6, ~34
         41      > JMP                                                      ->43
   20    42    >   UNSET_DIM                                                !5, !7
   16    43    > > JMP                                                      ->26
         44    >   FE_FREE                                                  $24
   24    45        BOOL_NOT                                         ~36     !1
         46      > JMPZ                                                     ~36, ->53
         47    >   INIT_FCALL                                               'array_slice'
         48        SEND_VAR                                                 !5
         49        SEND_VAL                                                 0
         50        SEND_VAL                                                 1
         51        DO_ICALL                                         $37     
         52        ASSIGN                                                   !5, $37
   25    53    > > JMPZ                                                     !5, ->61
         54    >   INIT_FCALL                                               'implode'
         55        SEND_VAL                                                 '%2C+'
         56        SEND_VAR                                                 !5
         57        DO_ICALL                                         $39     
         58        CONCAT                                           ~40     $39, '+ago'
         59        QM_ASSIGN                                        ~41     ~40
         60      > JMP                                                      ->62
         61    >   QM_ASSIGN                                        ~41     'just+now'
         62    > > RETURN                                                   ~41
   26    63*     > RETURN                                                   null

End of function time_elapsed_string

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.69 ms | 1398 KiB | 26 Q