3v4l.org

run code in 300+ PHP versions simultaneously
<?php function monthsBetween($startDate, $endDate) { $retval = ""; // Assume YYYY-mm-dd - as is common MYSQL format $splitStart = explode('-', $startDate); $splitEnd = explode('-', $endDate); if (is_array($splitStart) && is_array($splitEnd)) { $difYears = $splitEnd[0] - $splitStart[0]; $difMonths = $splitEnd[1] - $splitStart[1]; $difDays = $splitEnd[2] - $splitStart[2]; $retval = ($difDays > 0) ? $difMonths : $difMonths - 1; $retval += $difYears * 12; } return $retval; } echo monthsBetween('2014-06-16','2015-05-16'); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TVcfD
function name:  (null)
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   INIT_FCALL                                               'monthsbetween'
          1        SEND_VAL                                                 '2014-06-16'
          2        SEND_VAL                                                 '2015-05-16'
          3        DO_FCALL                                      0  $0      
          4        ECHO                                                     $0
   21     5      > RETURN                                                   1

Function monthsbetween:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 15, Position 2 = 17
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 39
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 34
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
Branch analysis from position: 17
filename:       /in/TVcfD
function name:  monthsBetween
number of ops:  41
compiled vars:  !0 = $startDate, !1 = $endDate, !2 = $retval, !3 = $splitStart, !4 = $splitEnd, !5 = $difYears, !6 = $difMonths, !7 = $difDays
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        ASSIGN                                                   !2, ''
    7     3        INIT_FCALL                                               'explode'
          4        SEND_VAL                                                 '-'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $9      
          7        ASSIGN                                                   !3, $9
    8     8        INIT_FCALL                                               'explode'
          9        SEND_VAL                                                 '-'
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $11     
         12        ASSIGN                                                   !4, $11
   10    13        TYPE_CHECK                                  128  ~13     !3
         14      > JMPZ_EX                                          ~13     ~13, ->17
         15    >   TYPE_CHECK                                  128  ~14     !4
         16        BOOL                                             ~13     ~14
         17    > > JMPZ                                                     ~13, ->39
   11    18    >   FETCH_DIM_R                                      ~15     !4, 0
         19        FETCH_DIM_R                                      ~16     !3, 0
         20        SUB                                              ~17     ~15, ~16
         21        ASSIGN                                                   !5, ~17
   12    22        FETCH_DIM_R                                      ~19     !4, 1
         23        FETCH_DIM_R                                      ~20     !3, 1
         24        SUB                                              ~21     ~19, ~20
         25        ASSIGN                                                   !6, ~21
   13    26        FETCH_DIM_R                                      ~23     !4, 2
         27        FETCH_DIM_R                                      ~24     !3, 2
         28        SUB                                              ~25     ~23, ~24
         29        ASSIGN                                                   !7, ~25
   15    30        IS_SMALLER                                               0, !7
         31      > JMPZ                                                     ~27, ->34
         32    >   QM_ASSIGN                                        ~28     !6
         33      > JMP                                                      ->36
         34    >   SUB                                              ~29     !6, 1
         35        QM_ASSIGN                                        ~28     ~29
         36    >   ASSIGN                                                   !2, ~28
   16    37        MUL                                              ~31     !5, 12
         38        ASSIGN_OP                                     1          !2, ~31
   18    39    > > RETURN                                                   !2
   19    40*     > RETURN                                                   null

End of function monthsbetween

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.24 ms | 1403 KiB | 16 Q