3v4l.org

run code in 300+ PHP versions simultaneously
<?php $date = '10.11.2021 14:00'; $diff = (new DateTime($date))->diff(new DateTime()); $lookup = [ 'y' => 'year', 'm' => 'month', 'd' => 'day', 'h' => 'hour', 'i' => 'minute', ]; foreach ($lookup as $property => $word) { if ($diff->$property) { if ($property === 'd' && $diff->$property >= 7) { $diff->w = (int)($diff->$property / 7); $property = 'w'; $word = 'week'; } $output = "for {$diff->$property} $word" . ($diff->$property !== 1 ? 's' : ''); break; } } echo $output ?? 'for mere seconds';
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 44
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 44
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 43
Branch analysis from position: 16
2 jumps found. (Code = 46) Position 1 = 18, Position 2 = 21
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 29
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 39
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
Branch analysis from position: 29
Branch analysis from position: 21
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 44
Branch analysis from position: 44
filename:       /in/InN7V
function name:  (null)
number of ops:  49
compiled vars:  !0 = $date, !1 = $diff, !2 = $lookup, !3 = $word, !4 = $property, !5 = $output
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '10.11.2021+14%3A00'
    4     1        NEW                                              $7      'DateTime'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        INIT_METHOD_CALL                                         $7, 'diff'
          5        NEW                                              $9      'DateTime'
          6        DO_FCALL                                      0          
          7        SEND_VAR_NO_REF_EX                                       $9
          8        DO_FCALL                                      0  $11     
          9        ASSIGN                                                   !1, $11
    6    10        ASSIGN                                                   !2, <array>
   14    11      > FE_RESET_R                                       $14     !2, ->44
         12    > > FE_FETCH_R                                       ~15     $14, !3, ->44
         13    >   ASSIGN                                                   !4, ~15
   15    14        FETCH_OBJ_R                                      ~17     !1, !4
         15      > JMPZ                                                     ~17, ->43
   16    16    >   IS_IDENTICAL                                     ~18     !4, 'd'
         17      > JMPZ_EX                                          ~18     ~18, ->21
         18    >   FETCH_OBJ_R                                      ~19     !1, !4
         19        IS_SMALLER_OR_EQUAL                              ~20     7, ~19
         20        BOOL                                             ~18     ~20
         21    > > JMPZ                                                     ~18, ->29
   17    22    >   FETCH_OBJ_R                                      ~22     !1, !4
         23        DIV                                              ~23     ~22, 7
         24        CAST                                          4  ~24     ~23
         25        ASSIGN_OBJ                                               !1, 'w'
         26        OP_DATA                                                  ~24
   18    27        ASSIGN                                                   !4, 'w'
   19    28        ASSIGN                                                   !3, 'week'
   21    29    >   ROPE_INIT                                     4  ~29     'for+'
         30        FETCH_OBJ_R                                      ~27     !1, !4
         31        ROPE_ADD                                      1  ~29     ~29, ~27
         32        ROPE_ADD                                      2  ~29     ~29, '+'
         33        ROPE_END                                      3  ~28     ~29, !3
         34        FETCH_OBJ_R                                      ~31     !1, !4
         35        IS_NOT_IDENTICAL                                         ~31, 1
         36      > JMPZ                                                     ~32, ->39
         37    >   QM_ASSIGN                                        ~33     's'
         38      > JMP                                                      ->40
         39    >   QM_ASSIGN                                        ~33     ''
         40    >   CONCAT                                           ~34     ~28, ~33
         41        ASSIGN                                                   !5, ~34
   22    42      > JMP                                                      ->44
   14    43    > > JMP                                                      ->12
         44    >   FE_FREE                                                  $14
   25    45        COALESCE                                         ~36     !5
         46        QM_ASSIGN                                        ~36     'for+mere+seconds'
         47        ECHO                                                     ~36
         48      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.86 ms | 1004 KiB | 13 Q