Jump to content

PHP Month Name


phaedo5

Recommended Posts

IMHO, here's a cleaner way:

<?php
// Start with current month
$curr_month = date('m');
for ($i = 0; $i < 12; $i++)
{
  echo date('F', mktime(0,0,0,$curr_month + $i)) . '<br />';
}
?>

 

**EDIT**

BTW, if you did want to use strtotime() for this, here's an easy way to modify the above:

<?php
for ($i = 0; $i < 12; $i++)
{
  echo date('F', strtotime("+{$i} month")) . '<br />';
}
?>

Link to comment
https://forums.phpfreaks.com/topic/92443-php-month-name/#findComment-473629
Share on other sites

It was my understanding that he didn't want to start with the current month, he wants to start with the first month.  Jan-Dec. 

 

Here's a refresher of the OP (note the part in bold):

 

I'd like to make a simple list of month names - January through December where the starting month is the current month

 

Either way, even starting with January, you could consolidate slightly like this:

<?php
for ($i = 0; $i < 12; $i++)
{
  echo date('F', strtotime("January 1 +{$i} month")) . '<br />';
}
?>

Link to comment
https://forums.phpfreaks.com/topic/92443-php-month-name/#findComment-473700
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.