I am trying to pick either Friday / Saturday or 3rd, 18th, 30th, 31st... which ever comes first.
Real example: Current date is Tuesday, January 10th, 2017.
Options:
- Friday, January 13th 2017
- Wednesday, January 18th 2017
My code should pick the Friday, January 13th 2017.
PHP
$dayOfWeekArray = ['friday', 'saturday'];
$dayOfMonthArray = [3, 18, 30, 31];
foreach ($dayOfWeekArray as $dayOfWeek) {
$nextDayDate = new DateTime("next $dayOfWeek");
foreach ($dayOfMonthArray as $dayOfMonth) {
# Continue if $nextDayDate is before, or equals, whichever date $dayOfMonth turns out to be.
# Otherwise, determine which comes first, $nextDayDate or $dayOfMonth
}
}
Question: How can I turn $dayOfMonth
into a date?