3v4l.org

run code in 300+ PHP versions simultaneously
<?php function percentYear($a, $b) { //A rather complex function that calculates the difference between two dates in terms of the year that they're in. //Returns a number that corresponds to the amount of years between the two provided dates. //Takes in two dates and returns the decimal of days per year for that specific year // I made this in order to fix the issue of leap years. if(strtotime($a)<strtotime($b)){ list($a, $b) = array($b, $a); } $aYearDay = date("z", strtotime($a)) + 1; $aYearDays = date("z", strtotime(date("Y", strtotime($a))."-12-31")) + 1; $aPercent = $aYearDay/$aYearDays; $bYearDay = date("z", strtotime($b)) + 1; $bYearDays = date("z", strtotime(date("Y", strtotime($b))."-12-31")) + 1; $bPercent = $bYearDay/$bYearDays; if(date("Y", strtotime($a))!=date("Y", strtotime($b))) { $aPercent += abs(date("Y", strtotime($a))-date("Y", strtotime($b))); } return abs($aPercent-$bPercent); } echo percentYear('2014-05-14', '2014-04-14');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jWEfV
function name:  (null)
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   INIT_FCALL                                               'percentyear'
          1        SEND_VAL                                                 '2014-05-14'
          2        SEND_VAL                                                 '2014-04-14'
          3        DO_FCALL                                      0  $0      
          4        ECHO                                                     $0
          5      > RETURN                                                   1

Function percentyear:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 17
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 89, Position 2 = 108
Branch analysis from position: 89
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 108
Branch analysis from position: 17
filename:       /in/jWEfV
function name:  percentYear
number of ops:  114
compiled vars:  !0 = $a, !1 = $b, !2 = $aYearDay, !3 = $aYearDays, !4 = $aPercent, !5 = $bYearDay, !6 = $bYearDays, !7 = $bPercent
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    8     2        INIT_FCALL                                               'strtotime'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $8      
          5        INIT_FCALL                                               'strtotime'
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                         $9      
          8        IS_SMALLER                                               $8, $9
          9      > JMPZ                                                     ~10, ->17
    9    10    >   INIT_ARRAY                                       ~11     !1
         11        ADD_ARRAY_ELEMENT                                ~11     !0
         12        FETCH_LIST_R                                     $12     ~11, 0
         13        ASSIGN                                                   !0, $12
         14        FETCH_LIST_R                                     $14     ~11, 1
         15        ASSIGN                                                   !1, $14
         16        FREE                                                     ~11
   11    17    >   INIT_FCALL                                               'date'
         18        SEND_VAL                                                 'z'
         19        INIT_FCALL                                               'strtotime'
         20        SEND_VAR                                                 !0
         21        DO_ICALL                                         $16     
         22        SEND_VAR                                                 $16
         23        DO_ICALL                                         $17     
         24        ADD                                              ~18     $17, 1
         25        ASSIGN                                                   !2, ~18
   12    26        INIT_FCALL                                               'date'
         27        SEND_VAL                                                 'z'
         28        INIT_FCALL                                               'strtotime'
         29        INIT_FCALL                                               'date'
         30        SEND_VAL                                                 'Y'
         31        INIT_FCALL                                               'strtotime'
         32        SEND_VAR                                                 !0
         33        DO_ICALL                                         $20     
         34        SEND_VAR                                                 $20
         35        DO_ICALL                                         $21     
         36        CONCAT                                           ~22     $21, '-12-31'
         37        SEND_VAL                                                 ~22
         38        DO_ICALL                                         $23     
         39        SEND_VAR                                                 $23
         40        DO_ICALL                                         $24     
         41        ADD                                              ~25     $24, 1
         42        ASSIGN                                                   !3, ~25
   13    43        DIV                                              ~27     !2, !3
         44        ASSIGN                                                   !4, ~27
   14    45        INIT_FCALL                                               'date'
         46        SEND_VAL                                                 'z'
         47        INIT_FCALL                                               'strtotime'
         48        SEND_VAR                                                 !1
         49        DO_ICALL                                         $29     
         50        SEND_VAR                                                 $29
         51        DO_ICALL                                         $30     
         52        ADD                                              ~31     $30, 1
         53        ASSIGN                                                   !5, ~31
   15    54        INIT_FCALL                                               'date'
         55        SEND_VAL                                                 'z'
         56        INIT_FCALL                                               'strtotime'
         57        INIT_FCALL                                               'date'
         58        SEND_VAL                                                 'Y'
         59        INIT_FCALL                                               'strtotime'
         60        SEND_VAR                                                 !1
         61        DO_ICALL                                         $33     
         62        SEND_VAR                                                 $33
         63        DO_ICALL                                         $34     
         64        CONCAT                                           ~35     $34, '-12-31'
         65        SEND_VAL                                                 ~35
         66        DO_ICALL                                         $36     
         67        SEND_VAR                                                 $36
         68        DO_ICALL                                         $37     
         69        ADD                                              ~38     $37, 1
         70        ASSIGN                                                   !6, ~38
   16    71        DIV                                              ~40     !5, !6
         72        ASSIGN                                                   !7, ~40
   17    73        INIT_FCALL                                               'date'
         74        SEND_VAL                                                 'Y'
         75        INIT_FCALL                                               'strtotime'
         76        SEND_VAR                                                 !0
         77        DO_ICALL                                         $42     
         78        SEND_VAR                                                 $42
         79        DO_ICALL                                         $43     
         80        INIT_FCALL                                               'date'
         81        SEND_VAL                                                 'Y'
         82        INIT_FCALL                                               'strtotime'
         83        SEND_VAR                                                 !1
         84        DO_ICALL                                         $44     
         85        SEND_VAR                                                 $44
         86        DO_ICALL                                         $45     
         87        IS_NOT_EQUAL                                             $43, $45
         88      > JMPZ                                                     ~46, ->108
   19    89    >   INIT_FCALL                                               'abs'
         90        INIT_FCALL                                               'date'
         91        SEND_VAL                                                 'Y'
         92        INIT_FCALL                                               'strtotime'
         93        SEND_VAR                                                 !0
         94        DO_ICALL                                         $47     
         95        SEND_VAR                                                 $47
         96        DO_ICALL                                         $48     
         97        INIT_FCALL                                               'date'
         98        SEND_VAL                                                 'Y'
         99        INIT_FCALL                                               'strtotime'
        100        SEND_VAR                                                 !1
        101        DO_ICALL                                         $49     
        102        SEND_VAR                                                 $49
        103        DO_ICALL                                         $50     
        104        SUB                                              ~51     $48, $50
        105        SEND_VAL                                                 ~51
        106        DO_ICALL                                         $52     
        107        ASSIGN_OP                                     1          !4, $52
   21   108    >   INIT_FCALL                                               'abs'
        109        SUB                                              ~54     !4, !7
        110        SEND_VAL                                                 ~54
        111        DO_ICALL                                         $55     
        112      > RETURN                                                   $55
   22   113*     > RETURN                                                   null

End of function percentyear

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.5 ms | 1407 KiB | 20 Q