title: How to group dates together in an array, removing any overlapping dates
body: <p>I have an array which holds start and end dates like the following:</p>
  
  <pre><code>$dates[] = array('start'=&gt; '2015-01-01', 'end'=&gt; '2016-05-01');
  $dates[] = array('start'=&gt; '2016-01-01', 'end'=&gt; '2016-09-11');
  $dates[] = array('start'=&gt; '2017-01-05', 'end'=&gt; '2018-02-01');
  $dates[] = array('start'=&gt; '2017-01-01', 'end'=&gt; '2017-05-05');
  </code></pre>
  
  <p>I want to merge the dates together and remove overlapping dates to produce a new array of dates without any overlap. The result of the above would be:</p>
  
  <pre><code>[0] =&gt; Array
      (
          [start] =&gt; 2015-01-01
          [end] =&gt; 2016-09-11
      )
  
  [1] =&gt; Array
      (
          [start] =&gt; 2017-01-01
          [end] =&gt; 2018-02-01
      )
  </code></pre>
  
  <p>I'm rather stuck on this. Any ideas on how this could be done?</p>