John
John

Reputation: 23

Array to replace name of Months with strtotime

Im having a little problem to replace the name of the months.

My Array:

$try= array(
       '01'=>'Jan123',
       '02'=>'Fev123',
       '03'=>'Mar123',
       '04'=>'Abr123',
       '05'=>'May123',
       '06'=>'June123',
       '07'=>'July123',
       '08'=>'Agos123',
       '09'=>'Set123',
       '10'=>'Out123',
       '11'=>'Nov123',
       '12'=>'Dez123'
   );

The date code:

<?php echo $try[date("m Y", strtotime("-10 month"))]; ?>

It is showing me blank, no output, any idea why?

Upvotes: 0

Views: 33

Answers (1)

Oleksii Semeniuk
Oleksii Semeniuk

Reputation: 308

This code output is 12 2017

<?php echo date("m Y", strtotime("-10 month")); ?>

and a keys in your array is 01, 02, 03 etc... try to use this code

<?php echo $try[date("m", strtotime("-10 month"))]; ?>

Upvotes: 1

Related Questions