PHP - Find longest date "streak" and "slump"
<p>I've currently got 2 dates in PHP - a 'start' date and an 'end' date.  I have then created an array of dates, using a function I found called <a href="http://boonedocks.net/mike/archives/137-Creating-a-Date-Range-Array-with-PHP.html" rel="nofollow"><code>createDateRangeArray</code></a> (<code>$date_range</code>).  For simplicity, the end date will always be <em>today's date</em>.</p>

<p>I've also got a separate array that contains a bunch of dates (<code>$valid_dates</code>) that will always fall between the start and end dates mentioned above.  On those dates, 'something' happened - in this case, a training session.</p>

<p>I'm trying to get my head around getting the following:</p>

<ul>
<li>A range of dates similar to the <code>$date_range</code> array, populated with TRUE or FALSE based on whether or not a training session happened on that date.  I'm happy for this to be an assoc array with keys named <code>date</code> and, say, <code>session_found</code> (bool).</li>
<li>The longest 'streak' i.e. the longest consecutive number of days that training sessions occurred.</li>
<li>The longest 'slump' i.e. the longest consecutive number of days that training sessions did NOT occur.</li>
</ul>

<p>Can someone point me in the right direction for getting the above info without using a <code>foreach</code> on the contents of the <code>$date_range</code> array and then having to use another <code>foreach</code> for the <code>$valid_dates</code> array on each item in the <code>$date_range</code> array?  That is horribly inefficient ...</p>

<p>Sorry if I've over-complicated things with all that info but any help would be much appreciated.</p>

<p>I'm currently using PHP 5.4 on Debian Wheezy, if that helps (typical LAMP stack).</p>

<p>Thanks</p>
