Jump to content

[SOLVED] Date Array Problems


flyerball10

Recommended Posts

I have this code that count back in months for 1 year. For some reason it outputs MARCH twice. Any idea?

 

$month = array

('now',

'now -1 months',

'now -2 months',

'now -3 months',

'now -4 months',

'now -5 months',

'now -6 months',

'now -7 months',

'now -8 months',

'now -9 months',

'now -10 months',

'now -11 months');

 

foreach ($month as $a) {

 

$date=strtotime($a);

$date=date("F Y", $date);

 

echo $date.'<br>';

 

}

 

/////Output

 

June 2007

May 2007

April 2007

March 2007

March 2007

January 2007

December 2006

November 2006

October 2006

September 2006

August 2006

July 2006

Link to comment
Share on other sites

Ditto.

 

<?php

$month = array
($first = date('Y-m-15'),
"$first -1 months",
"$first -2 months",
"$first -3 months",
"$first -4 months",
"$first -5 months",
"$first -6 months",
"$first -7 months",
"$first -8 months",
"$first -9 months",
"$first -10 months",
"$first -11 months");

foreach ($month as $a) echo date("F Y\n", strtotime($a));

?>

 

Output

June 2007

May 2007

April 2007

March 2007

February 2007

January 2007

December 2006

November 2006

October 2006

September 2006

August 2006

July 2006

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.