3v4l.org

run code in 300+ PHP versions simultaneously
<?php $startDate = '2001-04-20'; $endDate = '2015-11-29'; $diff = (new DateTime($startDate))->diff(new DateTime($endDate)); $lookup = [ 'y' => 'Year', 'm' => 'Month', 'd' => 'Day', ]; $elements = []; foreach ($lookup as $property => $word) { if ($diff->$property) { $elements[] = "{$diff->$property} $word" . ($diff->$property !== 1 ? 's' : ''); } } echo implode(' : ', $elements);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 33
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 33
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 32
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 28
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 32
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
filename:       /in/StLHX
function name:  (null)
number of ops:  40
compiled vars:  !0 = $startDate, !1 = $endDate, !2 = $diff, !3 = $lookup, !4 = $elements, !5 = $word, !6 = $property
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '2001-04-20'
    4     1        ASSIGN                                                   !1, '2015-11-29'
    5     2        NEW                                              $9      'DateTime'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
          5        INIT_METHOD_CALL                                         $9, 'diff'
          6        NEW                                              $11     'DateTime'
          7        SEND_VAR_EX                                              !1
          8        DO_FCALL                                      0          
          9        SEND_VAR_NO_REF_EX                                       $11
         10        DO_FCALL                                      0  $13     
         11        ASSIGN                                                   !2, $13
    7    12        ASSIGN                                                   !3, <array>
   13    13        ASSIGN                                                   !4, <array>
   14    14      > FE_RESET_R                                       $17     !3, ->33
         15    > > FE_FETCH_R                                       ~18     $17, !5, ->33
         16    >   ASSIGN                                                   !6, ~18
   15    17        FETCH_OBJ_R                                      ~20     !2, !6
         18      > JMPZ                                                     ~20, ->32
   16    19    >   FETCH_OBJ_R                                      ~22     !2, !6
         20        ROPE_INIT                                     3  ~24     ~22
         21        ROPE_ADD                                      1  ~24     ~24, '+'
         22        ROPE_END                                      2  ~23     ~24, !5
         23        FETCH_OBJ_R                                      ~26     !2, !6
         24        IS_NOT_IDENTICAL                                         ~26, 1
         25      > JMPZ                                                     ~27, ->28
         26    >   QM_ASSIGN                                        ~28     's'
         27      > JMP                                                      ->29
         28    >   QM_ASSIGN                                        ~28     ''
         29    >   CONCAT                                           ~29     ~23, ~28
         30        ASSIGN_DIM                                               !4
         31        OP_DATA                                                  ~29
   14    32    > > JMP                                                      ->15
         33    >   FE_FREE                                                  $17
   19    34        INIT_FCALL                                               'implode'
         35        SEND_VAL                                                 '+%3A+'
         36        SEND_VAR                                                 !4
         37        DO_ICALL                                         $30     
         38        ECHO                                                     $30
         39      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
135.06 ms | 1004 KiB | 14 Q