View Full Version : Validating times with array and foreach

06-16-2009, 04:22 PM
My db holds info on lessons which the user books with checkboxes. Their selections get passed to a foreach loop which grabs the the rows from the database. Like so...

foreach($checkBox as $k => $id_selected)
$lessons= queryClass("SELECT start, end FROM lessons WHERE lesson_id = '$id_selected' ");

// Store start and end times

echo "<br>";
echo $startTimes[] = $lessons['start'];
echo "<br>";
echo $endTimes[] = $lessons['end'];

As you can see in this loop I am grabbing the start and end time, echoing it and storing it in an array. However, I need to then check the start and end time of each selection against eachother, in order to find overlaps. I know how to do this with timestamps etc but how would I go through these stored times in the array. I tried another foreach but it didn't do it.

Also if I just put echo $startTimes[0]; then it outputs another two copies of the start time. :confused:

Anyone got any ideas? I think im almost there. Many thanks