I’m trying to generate a list of dates between a start date and and end date, and there is a checkbox with Monday to Friday as it’s choices.
I want to put the choices into an array which then filters out what days there are between the 2 dates (eg. Oct 1 start, Oct 31st end, checkbox only selected mondays). I can’t seem to get the checkbox to dump it’s values into an array. Here’s what I’ve written so far:
$start_date_input = strtotime(get_field('start_date'));
$end_date_input = strtotime(get_field('end_date'));
$choices = get_field('choices');
//while start date is less/equal to end date:
while ($start_date_input <= $end_date_input) {
//if the selected days are in the array:
if (in_array(date('l', $start_date_input), $choices)) {
//display it like 'day Month Date, Year'
$dates[] = date('l F j, Y', $start_date_input);
}
$start_date_input = strtotime('+1 day', $start_date_input);
}
the choices variable is where the checkbox should dump all the days.
solved.
The issue was that the checkbox values were in lowercase (monday), when the argument against it was for uppercase. Once I changed the values the dropbox would show the dates.