title: How to find free time slot based on available time slot and booked time slot?
body: <p>I have one user A. The User A is available for 10:45:00 to 18:45:00.  means he can accept appointments during that time.</p>
  
  <p>so suppose, User A has two booked appointments:<br>
  (1) 11:15:00 to 12:15:00 and<br>
  (2) 13:30:00 to 15:45:00  </p>
  
  <p>There is minimum 10 minutes gap between two appointment.</p>
  
  <p>So now User A's free timing is:</p>
  
  <p>(1) 10:45:00 to 11:05:00  ( start time = 10:45:00, end time = 11:05:00 because user A have booked appointment which is start at 11:15:00, there is 10 min gap between time so end time is  11:05:00)   </p>
  
  <p>(2) 12:25:00 to 13:20:00   (start time = 12:25:00 because first booked appointment is finished on 12:15:00, there is 10 min gap between time so end time is  12:25:00, end time = 13:20:00 because 2nd booked appointment is started on 13:30:00, there is 10 min gap between time so end time is  13:20:00 )</p>
  
  <p>(3) 15:55:00 to 18:45:00  (same as above)</p>
  
  <p>means </p>
  
  <blockquote>
    <p>Total Time Slot:<br>
    10:45:00 to 18:45:00  </p>
    
    <p>Booked Time Slot:<br>
    11:15:00 to 12:15:00<br>
    13:30:00 to 15:45:00   </p>
    
    <p>Free Time Slot:<br>
    10:45:00 to 11:05:00<br>
    12:25:00 to 13:20:00<br>
    15:55:00 to 18:45:00  </p>
  </blockquote>
  
  <p><code>PHP CODE</code>: </p>
  
  <pre><code>$total_time = array(
      'time' =&gt; '11:15:00',
      'end_time' =&gt; '12:15:00'
  );
  
  $gettime = $this-&gt;db-&gt;query("select `appointment_id`, `time`, `end_time` from `tbl_appointment` where `date`='".$json['date']."'");
  if($gettime-&gt;num_rows()&gt;0) 
  {
      foreach($gettime-&gt;result_array() as $restime)
      {
          $booked_time[] = array(
              'time' =&gt; $restime['time'],
              'end_time' =&gt; $restime['end_time']
          );
      }
  }
  </code></pre>
  
  <p>I have no idea about how to implement it, so i have no other code. Just two array.<br>
  So question is based on available time and booked time, how to find free time?</p>
  
  <p>Thanks in advance.</p>