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; $periods = array( 'y' => ['jaar', 'jaren'], 'm' => ['maand', 'maanden'], 'w' => ['week', 'weken'], 'd' => ['dag', 'dagen'], 'h' => ['uur', 'uren'], 'i' => ['minuut', 'minuten'], 's' => ['seconde', 'seconden'] ); $parts = array(); foreach ($periods as $k => &$v) { if ($diff->$k) { $parts[] = $diff->$k . ' ' . $v[$diff->$k > 1]; } } if (!$full) $parts = array_slice($parts, 0, 1); return $parts ? implode(', ', $parts) . ' ago' : 'just now'; } echo time_elapsed_string('2020-03-21 00:30:16') . PHP_EOL; echo time_elapsed_string('2020-03-21 00:30:16', true) . PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WOmOR
function name:  (null)
number of ops:  12
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   INIT_FCALL                                               'time_elapsed_string'
          1        SEND_VAL                                                 '2020-03-21+00%3A30%3A16'
          2        DO_FCALL                                      0  $0      
          3        CONCAT                                           ~1      $0, '%0A'
          4        ECHO                                                     ~1
   33     5        INIT_FCALL                                               'time_elapsed_string'
          6        SEND_VAL                                                 '2020-03-21+00%3A30%3A16'
          7        SEND_VAL                                                 <true>
          8        DO_FCALL                                      0  $2      
          9        CONCAT                                           ~3      $2, '%0A'
         10        ECHO                                                     ~3
   34    11      > RETURN                                                   1

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

End of function time_elapsed_string

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.85 ms | 1442 KiB | 18 Q