I have an array called $selection that contains ascending time values from 09:00 to 18:00 in 15 minute intervals.
eg: $selection = array(09:00, 09:15, 09:30, 09:45, 10:00, 10:15, 10:30);
Some intervals could be missing, because this array is generated from some prior code which determines which times are available from google calendar (amongst other things). 09:00 isn't always the start time, sometimes the entire morning could be booked out.
I am using this array to create a drop down list.
foreach($selection as $slot) {
if ( $slot == $selection[0] ) {
print '<option value="'.$slot.'" selected="selected">'.date('H:i', strtotime($slot)).'</option>';
} else {
print '<option value="'.$slot.'">'.date('H:i', strtotime($slot)).'</option>';
} // end else
}
Problem
I am trying to add
<optgroup label="Morning"> .. </optgroup>
and
<optgroup label="Afternoon"> .. </optgroup>
Not sure how to do this. I have come to the conclusion that I need a while loop. Perhaps even adding extra information into the array before running the foreach loop.. not sure!
Would appreciate any help