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
https://forums.phpfreaks.com/topic/57757-solved-date-array-problems/
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

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.