I want to get an array of dates within a period. To do so I thought up a for loop (seems simple enough...) But when I run it even with for the dates of 1 month it times out.
This is my php:
$startdate = '2018-01-31';
$recurring = '2';
switch($recurring) {
case '1':
$period = '+1 day';
break;
case '2':
$period = '+1 week';
break;
case '3':
$period = '+1 month';
break;
case '4':
$period = '+3 months';
break;
case '5':
$perion = '+1 year';
break;
default:
$period = null;
break;
}
$dates = [];
if($period !== null) {
for($date = $startdate; $date < strtotime('+1 month', $startdate); strtotime($period, $date)) {
$dates[] = $date;
}
}
echo json_encode($dates);
$datein that loop?strtotime($period, $date)$period has the incrementstrtotime. Does it modify the timestamp passed as its second argument?strtotime($period, $date)to$date = strtotime($period, $date)did the trick. Thanks! @Don'tPanic