Algorithm to combine / merge date ranges
问题 I am trying to find the best way on how to merge date ranges into one database record (array element). This is the data I have: Array ( [0] => Array ( [id] => 18298 [start_date] => 2011-07-09 [end_date] => 2011-10-01 ) [1] => Array ( [id] => 18297 [start_date] => 2011-06-01 [end_date] => 2011-06-30 ) [2] => Array ( [id] => 17113 [start_date] => 2011-03-31 [end_date] => 2011-05-31 ) [3] => Array ( [id] => 20555 [start_date] => 2011-01-03 [end_date] => 2011-03-31 ) ) And after we combine them,