title: Getting a list of last day of month dates in PHP
body: <p>These answers don't quite do what I want:</p>
  
  <p><a href="https://stackoverflow.com/questions/1889758/getting-last-months-date-in-php">Getting last month&#39;s date in php</a>
  <a href="https://stackoverflow.com/questions/1686724/php-last-day-of-the-month">How to find the last day of the month from date?</a> </p>
  
  <p>I have the following code that is meant to print a select-box with all the last day of month dates from a given date:</p>
  
  <pre><code>            $last_case_date = $this-&gt;query_end_date();
              $increm_date = "2011-06-01";
  
              echo '&lt;select name = "end_interval"&gt;';
              $increm_date = date('Y-m-d', strtotime("$increm_date"));
              while($increm_date &lt;= $last_case_date) {
                  // next date is $increm_date + 1 month
                  $increm_date = date('Y-m-d', strtotime("$increm_date + 1 months"));
                  // then we want the last day of this new date
                  $month = substr($increm_date, 5, 2);
                  $year = substr($increm_date, 0, 4);
                  $increm_date = $this-&gt;last_day_of_month($month, $year);
                  echo '&lt;option value = "'.$increm_date.'" selected = "selected"'.'&gt;'.$increm_date.'&lt;/option&gt;';
              }
              echo '&lt;/select&gt;';
  </code></pre>
  
  <p>where <code>last_day_of_month</code> is this:</p>
  
  <pre><code>   function last_day_of_month($month = '', $year = '') {
          if(empty($month)) {
              $month = date('m');
          }
          if(empty($year)) {
              $year = date('Y');
          }
          $result = strtotime("{$year}-{$month}-01");
          $result = strtotime('-1 second', strtotime('+1 months', $result));
          return date('Y-m-d', $result);
      }
  </code></pre>
  
  <p>which I borrowed from <a href="http://lutrov.com/php-last-day-of-the-month-calculation" rel="nofollow noreferrer">here</a>.</p>
  
  <p>Strange thing that happens is that I get these dates:</p>
  
  <p><code>2011-07-31
  2011-08-31
  2011-10-31</code></p>
  
  <p>but no <code>2011-09-30</code> !  It probably has something to do with September only having 30 days or something right?</p>
  
  <p>Can anyone spot the problem?  I've been staring at it for ages....  Thank you :).</p>