trying to echo 3 months into my WordPress website according to the todays month. 1) This month 2) Next month 3) Third month.
I have an array with names of the months:
$months = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
];
To print out current month:
<?php echo $months[(int)date('m')-1]; ?>
To print out next month:
<?php echo $months[((int)date('m') == 12 ? 1 : (int)date('m') + 1)-1]; ?>
Both if these work just fine. But when I try to print out third month instead of January I get February. Could you help me figure out why?
<?php echo $months[((int)date('m') == 11 ? 1 : (int)date('m') == 12 ? 2 : (int)date('m') + 2)-1]; ?>
I get the answer 0, so it should be January, but seems that
(int)date('m') == 12 ? 2
part is executed, instead of the first one.