How to create an array with months

1

Good afternoon, I'm maintaining a code that shows a graph, the X axis presents the last 11 months and the current month, who wrote it manually entered the months and wanted to automate it, I thought to do it as follows :

$meses = array(date(m)-11, date(m)-10, date(m)-9, date(m)-8, date(m)-7, date(m)-6, date(m)-5, date(m)-4, date(m)-3, date(m)-2, date(m)-1, date(m));

The problem is that by doing so months will be shown in number form and I need it to appear in date (M) format, but the function does not accept subtraction 'date (M) -1';

    
asked by anonymous 28.11.2016 / 16:40

1 answer

0

Just after calculating the month, convert it to text:

function convert_date($before){
     return DateTime::createFromFormat('!m', (date('m')-$before))->format('F');
}

Then just use it this way:

$meses = array(
     convert_date(11),
     convert_date(10),
     convert_date(9),
     convert_date(8),
     convert_date(7),
     convert_date(6),
     convert_date(5),
     convert_date(4),
     convert_date(3),
     convert_date(2),
     convert_date(1)
 );
    
28.11.2016 / 17:19