I have this code that will print name of month up to current month, if the year is current year and print up to december
, if its not the current year.
The code is working, but I would like to ask:
- Is there any shortest code to get the same result?
$current_year = date("Y");
$current_month = date('n');
$year=2015;
if ($year==$current_year )
{
for($m=1; $m<=$current_month; ++$m){
$monthName=date('F', mktime(0, 0, 0, $m, 1)).'<br />';
//print up to current month
echo $monthName;
}
}
else
{
for($m=1; $m<=12; ++$m){
$monthName=date('F', mktime(0, 0, 0, $m, 1)).'<br />';
//print up to December
echo $monthName;
}
}