Been banging my head against the table for a while now looking at this function, I dont think its that hard..but I'm totally blocking on this, thought I'd try to enlist the help of some more brains out there 😃
Problem:
I'm writing a calendar/time management script where users can schedule tasks defined by a start time and an end time. When the user adds a new task, I want to make sure it doesnt conflict with an existing task.
The existing tasks are in a multi-dimensional array sorted by start time, lowest start time first. I need to run the task I'm trying to add against the array of existing tasks and make sure there are no conflicts. Sounds easy enough?
I've tried different approaches involving foreach and while. For instance:
foreach ($multiarray as $key => $row) {
if(!isset($multiarray[$key + 1])) $nextarray = array("start" => "999999999");
else $nextarray = $multiarray[$key + 1];
if ($start == $row['start']) die("Starts at same time as another appt");
if(($start > $row['start']) and ($start < $row['end'])) die("Starts in another appt");
if(($start < $row['start']) and ($end > $row['start'])) die("Ends in another appt");
if (($start > $row['end']) and ($start < $nextarray['start']) and ($end > $nextarray['start'])) die("Ends in another appt");
}
..and so forth.
But I'm still just unable to make a function that sorts out all conflicts! Am I approaching this wrong? Or do I just need to have a litre of coffee and give it another go! 😉