title: Get the last 12 months in PHP
body: <p>So here is an interesting problem I learned today.</p>
  
  <p>I need to populate an array with the last 12 months, starting with the past month. So in August 2011, the last 12 months will be Sep 2010 - July 2011. To do this, I am using:</p>
  
  <pre><code>for ($i = 1; $i &lt;= 12; $i++)
      $months[] = date("Y-m%", strtotime("-$i months"));
  </code></pre>
  
  <p>The code above works just fine on August 30. I get the last 12 months:</p>
  
  <pre><code>array
      0 =&gt; string '2011-07%' (length=8)
      1 =&gt; string '2011-06%' (length=8)
      2 =&gt; string '2011-05%' (length=8)
      3 =&gt; string '2011-04%' (length=8)
      4 =&gt; string '2011-03%' (length=8)
      5 =&gt; string '2011-02%' (length=8)
      6 =&gt; string '2011-01%' (length=8)
      7 =&gt; string '2010-12%' (length=8)
      8 =&gt; string '2010-11%' (length=8)
      9 =&gt; string '2010-10%' (length=8)
      10 =&gt; string '2010-09%' (length=8)
      11 =&gt; string '2010-08%' (length=8)
  </code></pre>
  
  <p>But when I run this on Aug 31, I get:</p>
  
  <pre><code>array
      0 =&gt; string '2011-07%' (length=8)
      1 =&gt; string '2011-07%' (length=8)
      2 =&gt; string '2011-05%' (length=8)
      3 =&gt; string '2011-05%' (length=8)
      4 =&gt; string '2011-03%' (length=8)
      5 =&gt; string '2011-03%' (length=8)
      6 =&gt; string '2011-01%' (length=8)
      7 =&gt; string '2010-12%' (length=8)
      8 =&gt; string '2010-12%' (length=8)
      9 =&gt; string '2010-10%' (length=8)
      10 =&gt; string '2010-10%' (length=8)
      11 =&gt; string '2010-08%' (length=8)
  </code></pre>
  
  <p>I have tried both Windows and Unix. Does anyone have a solution for this?</p>