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.
Here is my code:
$pay_cycles=5;
$period=30;
$arr = array();
for ($i=1;$i<=$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);
This is what prints
Array ( [0] => 2010-12-30 [1] => 2011-01-29 [2] => 2011-01-29 [3] => 2011-01-29 [4] => 2011-01-29 )
Thanks for looking