Displaying the list of months using mktime for the year 2012

Sboniso Marcus Nzimande picture Sboniso Marcus Nzimande · May 31, 2012 · Viewed 39.4k times · Source

Am am current facing a problem that need a solution ASAP.

I am trying to list all months of the current year(2012) by using the following code:

for ($m=1; $m<=12; $m++) {
     $month = date('F', mktime(0,0,0,$m));
     echo $month. '<br>';
     }

But am getting the following unexpected output:

January March March May May July July August October October December December

What am I doing wrong please help!!!

Answer

iWizard picture iWizard · May 31, 2012

Try this:

for ($m=1; $m<=12; $m++) {
     $month = date('F', mktime(0,0,0,$m, 1, date('Y')));
     echo $month. '<br>';
     }