我试图找到如何将日期范围合并到一个数据库记录(数组元素)的最佳方法.
这是我的数据:
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
)
)
在我们组合它们之后,数组(或数据库)应如下所示:
Array
(
[0] => Array
(
[merged_ids] => 18298
[start_date] => 2011-07-09
[end_date] => 2011-10-01
)
[1] => Array
(
[merged_ids] => 18297, 17113, 20555
[start_date] => 2011-01-03
[end_date] => 2011-06-30
)
)
是否有任何算法可以遍历所有元素/范围并将它们组合起来?哪种方式更好/更容易 – 通过数据库(MYSQL)或编码(PHP)?
任何建议都非常感谢.
谢谢!
更新:对不起,我没有提供足够的信息:我们应该合并任何连续和重叠的日期范围.