Setting PHP variables for 2 years back and 2 years in the future
Only three-four line code rquired for getting required result:-

&lt;?php

$date = date("Y"); //current year

$date_range = range($date-2, $date+2);//get year range

//print_r($date_range); //print year range

echo implode(',',$date_range);//comma seperated date range


Output:- https://eval.in/944817