I want to execute a condition during a loop between 2 dates.
This is my code :
for($i = $periodStartAt; $periodStartAt <= $endAt; $i->modify('+1 day')){
// when it's 12 days
// when it's 2 days (after the 12 days)
// when it's 12 days (after the 2 days)
// etc.....
}
Anyone can help with this algorithm ?
Thanks in advance !
You can consider a period to be 14 days long, which could be split in two subperiods - first of 12 days and the second of 2 days.
So each step of your loop could process 14 days:
$periodStartAt = 0;
while(true) {
$periodStartAt += 12; // first sub-period
if ($periodStartAt > $endAt) break;
//do something when first sub-period reached
$periodStartAt += 2; //second sub-period
if ($periodStartAt > $endAt) break;
//do something when second sub-period reached
}