需要PHP函数,以确保所有日期都在一系列日期范围内进行计算

I'm working in PHP and I have a list of date ranges. I need an elegant way to look between the earliest and latest dates in the range and insure every day is accounted for by one of the ranges. For example:

$dates = array(  array('2012-01-01', '2012-01-10'),
                 array('2012-01-11', '2012-02-06'),
                 array('2012-02-08', '2012-03-01'),
                 array('2012-03-02', '2012-04-01')
              );

If you look closely at my sample data above, you'll see that February 7 isn't accounted for, and it falls within the overall date range I'm working with (1/1/12 to 4/1/12)... so I need to identify both elements that flank the missing 2012-02-07 (in this case, the 2nd and 3rd elements of the array).

Interval Trees might be a good solution.

Build an interval tree, and check if the intersection with the total range of dates [min,max] is overlapping the range represented by the intervals tree.

You can sort the ranges by start date, then traverse the sort list to look for any gaps.