3v4l.org

run code in 500+ PHP versions simultaneously
<?php $today = DateTime::createFromFormat('d.m.Y', '17.06.2019'); $dates = [ '17.06.2016', '19.06.2016', '15.06.2016', ]; foreach ($dates as $date) { $mpsAgeT = DateTime::createFromFormat('d.m.Y', $date); // Find year difference $years = $today->format('Y') - $mpsAgeT->format('Y'); // Add to original date (sets it to the same date of the current year) // Only add if the date has passed if ($today > $mpsAgeT->modify('+' . $years . ' years')) { $years++; } /* 17.06.2019 and 17.06.2016 - should returns me 3 17.06.2019 and 19.06.2016 - should returns me 3 17.06.2019 and 15.06.2016 - should returns me 4 */ print $date . " -> " . $years . "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 34
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 34
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 29
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 29
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
filename:       /in/6HUSG
function name:  (null)
number of ops:  36
compiled vars:  !0 = $today, !1 = $dates, !2 = $date, !3 = $mpsAgeT, !4 = $years
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   INIT_STATIC_METHOD_CALL                                      'DateTime', 'createFromFormat'
          1        SEND_VAL                                                     'd.m.Y'
          2        SEND_VAL                                                     '17.06.2019'
          3        DO_FCALL                                          0  $5      
          4        ASSIGN                                                       !0, $5
    5     5        ASSIGN                                                       !1, <array>
   11     6      > FE_RESET_R                                           $8      !1, ->34
          7    > > FE_FETCH_R                                                   $8, !2, ->34
   12     8    >   INIT_STATIC_METHOD_CALL                                      'DateTime', 'createFromFormat'
          9        SEND_VAL                                                     'd.m.Y'
         10        SEND_VAR                                                     !2
         11        DO_FCALL                                          0  $9      
         12        ASSIGN                                                       !3, $9
   15    13        INIT_METHOD_CALL                                             !0, 'format'
         14        SEND_VAL_EX                                                  'Y'
         15        DO_FCALL                                          0  $11     
         16        INIT_METHOD_CALL                                             !3, 'format'
         17        SEND_VAL_EX                                                  'Y'
         18        DO_FCALL                                          0  $12     
         19        SUB                                                  ~13     $11, $12
         20        ASSIGN                                                       !4, ~13
   18    21        INIT_METHOD_CALL                                             !3, 'modify'
         22        CONCAT                                               ~15     '%2B', !4
         23        CONCAT                                               ~16     ~15, '+years'
         24        SEND_VAL_EX                                                  ~16
         25        DO_FCALL                                          0  $17     
         26        IS_SMALLER                                                   $17, !0
         27      > JMPZ                                                         ~18, ->29
   19    28    >   PRE_INC                                                      !4
   27    29    >   CONCAT                                               ~20     !2, '+-%3E+'
         30        CONCAT                                               ~21     ~20, !4
         31        CONCAT                                               ~22     ~21, '%0A'
         32        ECHO                                                         ~22
   11    33      > JMP                                                          ->7
         34    >   FE_FREE                                                      $8
   28    35      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
166.79 ms | 2252 KiB | 13 Q