PHP: Succint and scalable function to get what financial year we are in I have the below

private function yearMenu() {
    $m = date('m');
    $y = date('Y');

    if (($m&gt;3 &amp;&amp; $y==2019) || ($m&lt;4 &amp;&amp; $y==2020)){
        $menu = 1;
    }
    if (($m&gt;3 &amp;&amp; $y==2020) || ($m&lt;4 &amp;&amp; $y==2021)){
        $menu = 2;
    }
    if (($m&gt;3 &amp;&amp; $y==2021) || ($m&lt;4 &amp;&amp; $y==2022)){
        $menu = 3;
    }
    if (($m&gt;3 &amp;&amp; $y==2022) || ($m&lt;4 &amp;&amp; $y==2023)){
        $menu = 4;
    }
    if (($m&gt;3 &amp;&amp; $y==2023) || ($m&lt;4 &amp;&amp; $y==2024)){
        $menu = 5;
    }
    if (($m&gt;3 &amp;&amp; $y==2024) || ($m&lt;4 &amp;&amp; $y==2025)){
        $menu = 6;
    }

    return $menu;
}


This code works as intended i.e. I want to be able to give each financial year an integer based on 2019-2020 being the base at value 1 and it increasing each year onward

I was wondering if there was a more succinct and scalable way to do this?

Thanks
Ways of improving:

According to information provided the crucial function's purpose is "to return a particular menu number for the current year". Thus, the function name would be more descriptive with name getFinYearMenuNumber.

The preconditions are:


your financial year flows through "April to April" month periods
there's starting year 2019 and ending year 2015 for the whole interval.To make the function more unified those boundaries could be passed as input parameters:

function getFinYearMenuNumber($yearFrom, $yearTo)



The main issue of the current approach is that it'll inevitably perform 5 excessive if checks (they could be at least mutually exclusive if ... else if ... else if ...).

Instead, we can just perform 2 subsequent checks: 


if the current year falls in the needed interval
if the current month is following or preceding the starting month (April)




The final version:

function getFinYearMenuNumber($yearFrom, $yearTo) {
    $curr_month = (int) date('m');    # current month number
    $curr_year = (int) date('Y');     # current year
    $curr_date = new DateTime();

    if ((new DateTime("$yearFrom-04")) &lt;= $curr_date &amp;&amp; $curr_date &lt;= (new DateTime("$yearTo-04"))) {
        if ($curr_month &gt; 3) {
            return $curr_year - $yearFrom + 1; 
        } else if ($curr_month &lt; 4) {
            return $curr_year - $yearFrom; 
        }
    }

    return 0;
}

print_r(getFinYearMenuNumber(2019, 2025));