Possible Duplicate:
Check for consecutive dates within a set and return as range
I have an array of dates which is obtained from a mySQL query. I need to divide the array into multiple arrays so that the dates in each array are contiguous.
So, if I start with
$datearray = array("2013-05-05", "2013-05-06", "2013-05-07", "2013-05-08", "2013-06-19", "2013-06-20", "2013-06-21");
I need to be able to split that into
$firstdatearray = array("2013-05-05", "2013-05-06", "2013-05-07", "2013-05-08");
$seconddatearray = array("2013-06-29", "2013-06-30", "2013-07-01");
Finally I will be able to print
5 – 8 Mar, 29 Jun – 1 Jul
How can I do that? I haven’t a clue where to start.
THIS IS THE COMPLETE WORKING ANSWER. (Enjoy!)
You’ll have to loop through each value in $datearray
This is the output: