I am trying to build a loop that echoes each month of the year until the current month. My foreach
loop just stays on the start and doesn't progress through the rest of the range. Here is my code:
$startMonth = '01';
$endMonth = date('m');
foreach (range($startMonth, $endMonth) as $month) {
$dataValue = date('n', $month);
echo '<td class="month" data-value="';
echo $dataValue;
echo '" data-id="' . $incrementYear . '"><a href="/Archive/view/';
echo $incrementYear;
echo '/';
echo date('m', $month);
echo '">';
echo date('F', $month);
echo '</a></td>';
}
Here is the output:
January January January January January January
Each of the months has the correct link for what January should have, but for some reason, the range never leaves "01" which is the $startMonth
and I'm not sure why. I was thinking it had something to do with integer vs. string, but removing the '
from $startMonth = '01';
to make it an integer, but that didn't work either.
As far as I understand them, I am using the range correctly.
What am I missing here?
EDIT
$dataValue can be commented out and I will still get
January
6 times, its just the link will have a data-value different than what I want. This variable has no effect on the month itself.-
If I change the bottom line of code from
echo date('F', $month);
toecho $month;
I get:1 2 3 4 5 6