title: PHP - Range of consecutive true array keys
body: <p>I have the following dataset:</p>
  <pre><code>$slots = [
    &quot;00:00&quot; =&gt; true
    &quot;00:15&quot; =&gt; true
    &quot;00:30&quot; =&gt; true
    &quot;00:45&quot; =&gt; true
    &quot;01:00&quot; =&gt; false
    &quot;01:15&quot; =&gt; false
    &quot;01:30&quot; =&gt; false
    &quot;01:45&quot; =&gt; false
    &quot;02:00&quot; =&gt; true
    &quot;02:15&quot; =&gt; false
    &quot;02:30&quot; =&gt; false
    &quot;02:45&quot; =&gt; false
    &quot;03:00&quot; =&gt; true
    &quot;03:15&quot; =&gt; true
    &quot;03:30&quot; =&gt; true
    &quot;03:45&quot; =&gt; false
    &quot;04:00&quot; =&gt; false
    &quot;04:15&quot; =&gt; false
    &quot;04:30&quot; =&gt; false
    &quot;04:45&quot; =&gt; false
    &quot;05:00&quot; =&gt; false
    &quot;05:15&quot; =&gt; false
    &quot;05:30&quot; =&gt; false
    &quot;05:45&quot; =&gt; false
    &quot;06:00&quot; =&gt; false
    &quot;06:15&quot; =&gt; false
    &quot;06:30&quot; =&gt; false
    &quot;06:45&quot; =&gt; false,
    .........
  ];
  </code></pre>
  <p>I need to come up with an efficient solution to get intervals for when the values is true. Like in the above dataset i need to generate something like this:</p>
  <pre><code>$trueSlots = ['00:00-00:45', '02:00-02:00', '03:00-03:30'];
  </code></pre>
  <p>I'm having a bad day and seem to over-complicate it.</p>
  <p><strong>edit:</strong>
  What can work too is the following return format:</p>
  <pre><code>$trueSlots = [
    '00:00' =&gt; '00:45',
    '02:00' =&gt; '02:00',
    '03:00' =&gt; '03:30',
  ];
  </code></pre>