Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying the list of months using mktime for the year 2012

Tags:

date

php

mktime

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!!!

like image 277
Sboniso Marcus Nzimande Avatar asked Nov 26 '22 20:11

Sboniso Marcus Nzimande


2 Answers

Try this:

for ($m=1; $m<=12; $m++) {
     $month = date('F', mktime(0,0,0,$m, 1, date('Y')));
     echo $month. '<br>';
     }
like image 200
iWizard Avatar answered May 11 '23 20:05

iWizard


Months are same for every year

$array = array("January", "February",.....);
for ($m=0; $m<12; $m++) {
     echo $array[$m]. '<br>';
     }
like image 30
Raab Avatar answered May 11 '23 20:05

Raab