Adding number of days to a previous date inside incrementing variable for loop
<p>I am working on a function which adds a number of days to a date inside an incrementing variable loop. I am having a problem getting the date from the previous loop to add the next 30 days to that date. This seems to be working for the first 2 loops then breaks and I cannot figure out the correct code to get the previous dates.</p>

<p>Here is my code:</p>

<pre><code>$pay_cycles=5;
$period=30;

 $arr = array();
 for ($i=1;$i&lt;=$pay_cycles;$i++) {

 //if first loop get todays date
 if($i==1){
 $due = date("Y-m-d");

 //else add to previous date
 } else {
 $time = strtotime ( '+'.$period.' day' , strtotime ( $due-1 ) ) ;
 $due = date("Y-m-d", $time); 
 }
   $arr[] = $due;
 }
 print_r($arr);
</code></pre>

<p>This is what prints</p>

<pre><code>Array ( [0] =&gt; 2010-12-30 [1] =&gt; 2011-01-29 [2] =&gt; 2011-01-29 [3] =&gt; 2011-01-29 [4] =&gt; 2011-01-29 )
</code></pre>

<p>Thanks for looking</p>
