PHP: get last 6 months in format month year
问题 Is there a way in PHP to get the current and the previous 5 months in the following format? April 2014 March 2014 February 2014 January 2014 December 2013 November 2013 回答1: Have you tried following: <?php echo date('F, Y'); for ($i = 1; $i < 6; $i++) { echo date(', F Y', strtotime("-$i month")); } Let me know, if this wont work. 回答2: Try this for ($j = 0; $j <= 5; $j++) { echo date("F Y", strtotime(" -$j month")); } 回答3: Use strtotime and date for( $i = 0; $i <= 5 ; $i++) { print date("F Y",