title: PHP: DatePeriod with last day of month
body: <p>I'd like to work with PHP DateInterval to iterate through months:</p>
  
  <pre><code>$from = new DateTime();
  $from-&gt;setDate(2014, 1, 31);
  
  $period = new DatePeriod($from, new DateInterval('P1M'), 12);
  </code></pre>
  
  <p>I'd expect it to returns 31 January, 28 February (as the DateInterval is 1 month), but it actually returns 31 January, 3 March, 3 of April... hence skipping February.</p>
  
  <p>Is there any way to do this simply?</p>
  
  <p>Thanks!</p>
  
  <p>EDIT : as a refernece, here is a solution that seems to cover most use cases:</p>
  
  <pre><code>$date = new DateTime('2014-01-31');
  $start = $date-&gt;format('n');
  
  for ($i = 0; $i &lt; 28; $i++) {
    $current = clone $date;
    $current-&gt;modify('+'.$i.' month');
  
    if ($current-&gt;format('n') &gt; ($start % 12) &amp;&amp; $start !== 12) {
      $current-&gt;modify('last day of last month');
    }
  
    $start++;
  
    echo $current-&gt;format('Y-m-d').PHP_EOL;
  }
  </code></pre>