title: print time intervals between start time and end time using php
body: <p>I have to print the time intervals between to times using php.</p>
  
  <p>I have an inputs like</p>
  
  <pre><code>$start_time = "09:45:00";
  $end_time = "2:45:00";
  $interval = "+60 minutes";
  
  im printing array like 
  
  $tarray = ['09:45:00', '10:45:00', '11:45:00', '12:45:00', '1:45:00', '2:45:00'];
  </code></pre>
  
  <p>But i want to print array like</p>
  
  <pre><code>$result = ['09:45:00-10:45:00', '10:45:00-11:45:00', '11:45:00-12:45:00', '12:45:00-1:45:00', '1:45:00'-'2:45:00'];
  </code></pre>
  
  <p>And from  result array i have to separate am and pm times also.</p>
  
  <pre><code>$am_times = ['09:45:00-10:45:00', '10:45:00-11:45:00', '11:45:00-12:45:00'];
  $pm_times = ['12:45:00-1:45:00', '1:45:00'-'2:45:00'];
  </code></pre>
  
  <p>I have tried like below </p>
  
  <pre><code>  Illuminate\Support\Collection Object
  (
  [items:protected] =&gt; Array
      (
          [0] =&gt; stdClass Object
              (
                  [id] =&gt; 121
                  [showroom_id] =&gt; 22
                  [showroom_open_day] =&gt; Monday
                  [showroom_start_time] =&gt; 01:15:00
                  [showroom_end_time] =&gt; 03:15:00
                  [created_at] =&gt; 2017-07-03 10:43:36
                  [updated_at] =&gt; 2017-07-03 10:43:36
              )
  
          [1] =&gt; stdClass Object
              (
                  [id] =&gt; 122
                  [showroom_id] =&gt; 22
                  [showroom_open_day] =&gt; Tuesday
                  [showroom_start_time] =&gt; 02:15:00
                  [showroom_end_time] =&gt; 22:00:00
                  [created_at] =&gt; 2017-07-03 10:43:36
                  [updated_at] =&gt; 2017-07-03 10:43:36
              )
  
          [2] =&gt; stdClass Object
              (
                  [id] =&gt; 123
                  [showroom_id] =&gt; 22
                  [showroom_open_day] =&gt; Wednesday
                  [showroom_start_time] =&gt; 02:00:00
                  [showroom_end_time] =&gt; 09:00:00
                  [created_at] =&gt; 2017-07-03 10:43:36
                  [updated_at] =&gt; 2017-07-03 10:43:36
              )
  
      )
  
  )
  
    foreach ($showroom_timings_result as $st) 
      {            
         $start          = $st-&gt;showroom_start_time;
         $end            = $st-&gt;showroom_end_time;
         $interval       = '+60 minutes';
         $times_array[$st-&gt;showroom_open_day] = getTimeSlots($start, $end, $interval);
      }
  
    function getTimeSlots($start='00:00:00', $end='23:45:00', $interval='+60 minutes') {
      $start_str      = strtotime($start);
      $end_str        = strtotime($end);
      $now_str        = $start_str;
  
      $data = [];
  
      while($now_str &lt;= $end_str){
          $data[]     = date('H:i:s', $now_str);
          $now_str    = strtotime($interval, $now_str);
      }
  
      return $data;
   }
  </code></pre>
  
  <p>Please help me out, Thanks in Advance.</p>