title: Next month, same day in PHP
body: <p>I have an "event" that needs to be scheduled the same day of every month. </p>
  
  <p>Say you set the start date on the 1st May you should get the next events on the 1st of Jun, 1 Jul etc. The problem comes with a start date on the 31st (the next ones could be 30 or 28 depending on the month).</p>
  
  <p>Considering that there are months with different numbers of days (28, 30, 31) depending on the month itself and the year... what would be an easy way to setup this?</p>
  
  <p>Consider the following (and flawed) nextmonth function:</p>
  
  <pre><code>$events = array()
  
  function nextmonth($date) {
     return $date+(60*60*24*30);
  }
  $curr = $start;
  while($curr &lt; $end) {
      $events[ = $curr;
      $curr = nextmonth($curr);
  }
  </code></pre>
  
  <p>Edited to add: The problem for me is, simply enough, how to solve what the number of days of any given month is and thus get the next corresponding date.</p>