Return timeslot array based on begin and end time in PHP
<p>I need your help with the following issue. I'm building a website, using PHP, on which I'd like to display a calendar showing the days of the week, with each day subdivided into 3 timeslots. These timeslots are either free, or booked, in which case that timeslot is not selectable. </p>

<p>So far so good, but the problem lies in displaying the timeslots as booked. I'm getting the booking data from a script which gives me an start date and time, and an end date and time. These date/time stamps can be anything and aren't bound to timeslot times. They can be on the same day, or span multiple days. The timeslots are the same for each day: from 9 to 13, 13 to 17, and 19 to 23 hrs. </p>

<p>For example, say I have a start time of 17-12-2012 13:00, and an end time of 18-12-2012 11:00, I want my function to give me an array like this:</p>

<pre><code>array(1) {
  ["meetingroom1_booked"]=&gt;
  array(3) {
    [0]=&gt;
    array(2) {
      ["day"]=&gt;
      string(10) "2012-12-17"
      ["timeslot"]=&gt;
      string(1) "2"
    }
    [1]=&gt;
    array(2) {
      ["day"]=&gt;
      string(10) "2012-12-17"
      ["timeslot"]=&gt;
      string(1) "3"
    }
    [2]=&gt;
    array(2) {
      ["day"]=&gt;
      string(10) "2012-12-18"
      ["timeslot"]=&gt;
      string(1) "1"
    }
  }
}
</code></pre>

<p>I've been racking my brain over this, but can't come up with a good solution that deals with start-end times span multiple days. With begin and end time on a single day, it's no problem: I can compare the start-end hours to the timeslot hours. This doesn't work for multiple days though of course. Any pointers in the right direction are highly appreciated! Thanks!</p>
