I need to loop 6 months (current month and past) with year. my code is : [php]
$months = array();
for ($i = 0; $i < 6; $i++) {
$timestamp = mktime(0, 0, 0, date(‘n’) - $i, 1);
$months[date(‘n’, $timestamp)] = date(‘F’, $timestamp);
$m = date(‘F’, $timestamp);
echo date(‘Y-m’, strtotime($m)) ;
echo ‘
’ ;
}[/php]
but problem is it is looping like :
2015-01
2015-12
2015-11
2015-10
2015-09
2015-08
but i need like :
2015-01
2014-12
2014-11
2014-10
2014-09
2014-08
Please tell me correct code.
Thanks.