title: PHP Range of Times
body: <p>I need a list of times that will be used for collection times. The user will select when collections starts, ends and the intervals between these times. </p>
  
  <p>If i set:</p>
  
  <pre><code>Start: 11:00 
  End: 20:00 
  Interval: 30
  </code></pre>
  
  <p>It will correctly produce a list from 11:00 to 20:00 with 30 minute intervals between... eg <code>11:00, 11:30, 12:00, ... 19.00, 19.30, 20.00</code></p>
  
  <p>Now for the issue, if i set:</p>
  
  <pre><code>Start: 20:00 
  End: 03:00 
  Interval: 30
  </code></pre>
  
  <p>The following list it produced, the times are going backwards, going down from 8pm to 3am, when it should be going up! <code>20:00, 19:30, 19:00, ... 04.00, 03.30, 03.00</code> </p>
  
  <p>How can i adapt my code so that it always goes up? so it produces these results instead... <code>20:00, 20:30, 21:00, ... 02.00, 02.30, 03.00</code> </p>
  
  <p>Heres my code:</p>
  
  <pre><code>        $collectTimes = array();
          $range = range(strtotime($settingsCTS), strtotime($settingsCTE), $settingsCTI * 60);
          foreach ($range as $time) {
              $collectTimes[] = date("H:i", $time);
          }
  </code></pre>