title: How to generate a list of links for each X number of prior months?
body: <p>I'm attempting to generate a list of links, one for each month starting at the current month and working backwards for X number of months.</p>
  
  <p>I have something mostly working, with the exception that it is "skipping" the month of February 2013. Here is a screenshot of what I have now:</p>
  
  <p><img src="https://i.stack.imgur.com/QA3na.png" alt="enter image description here"></p>
  
  <p>Here is the code from the view template that is generating that list:</p>
  
  <pre><code>        &lt;?php for( $i = 1; $i &lt;= 8; $i++ ): ?&gt;
              &lt;li&gt;
                  &lt;?php $prior_time = strtotime( "-$i month" ); ?&gt;
                  &lt;?php $month = date( 'm', $prior_time ); ?&gt;
                  &lt;?php $year = date( 'Y', $prior_time ); ?&gt;
                  &lt;?php $day = date( 't', mktime( 0, 0, 0, $month, 1, $year ) ); ?&gt;
                  &lt;?php $prior_month_string = date( 'F', $prior_time ); ?&gt;
                  &lt;?php $prior_month_from = date( 'm/01/Y', $prior_time ); ?&gt;
                  &lt;?php $prior_month_to = date( "m/$day/Y", $prior_time ); ?&gt;
                  &lt;?php if( date( 'F', strtotime( $selected_from ) ) == $prior_month_string ): ?&gt;
                      &lt;?php echo $prior_month_string; ?&gt;
                  &lt;?php else: ?&gt;
                      &lt;a href='/claims?&lt;?php echo "from=$prior_month_from&amp;to=$prior_month_to"; ?&gt;'
                         data-from='&lt;?php echo $prior_month_from; ?&gt;'
                         data-to='&lt;?php echo $prior_month_to; ?&gt;'&gt;
                          &lt;?php echo $prior_month_string; ?&gt;
                      &lt;/a&gt;
                  &lt;?php endif; ?&gt;
              &lt;/li&gt;
          &lt;?php endfor; ?&gt;
  </code></pre>
  
  <p>The funny thing is, if I extend the <code>for</code> loop to run up through <code>$i &lt;= 18</code>, it <em>does</em> display February 2012. But for some reason, when attempting to display February 2013, it instead displays another March 2013 (example of issue shown in above screenshot).</p>
  
  <p>It seems like the issue is here:</p>
  
  <pre><code>$prior_time = strtotime( "-$i month" );
  </code></pre>
  
  <p>But, I am at a loss as to <em>why</em> and how to get around it.  Why does this algorithm spit out a second March 2013 instead of February 2013 and how can I get around this oddity?</p>