php - Loop through 2 dates and execute a condition each 12 days, 2 days, 12 days, 2 days, etc -
i want execute condition during loop between 2 dates.
this code :
for($i = $periodstartat; $periodstartat <= $endat; $i->modify('+1 day')){ // when it's 12 days // when it's 2 days (after 12 days) // when it's 12 days (after 2 days) // etc..... }
anyone can algorithm ?
thanks in advance !
you can consider period 14 days long, split in 2 subperiods - first of 12 days , second of 2 days.
so each step of loop process 14 days:
$periodstartat = 0; while(true) { $periodstartat += 12; // first sub-period if ($periodstartat > $endat) break; //do when first sub-period reached $periodstartat += 2; //second sub-period if ($periodstartat > $endat) break; //do when second sub-period reached }
Comments
Post a Comment