你去http://codepad.viper-7.com/EKo9ky
$dates = array(
array(1, "2012-10-07"),
array(1, "2012-10-08"),
array(1, "2012-10-09"),
array(1, "2012-10-10"),
array(2, "2012-10-07"),
array(2, "2012-10-08"),
array(2, "2012-10-09"),
array(2, "2012-10-10"),
array(3, "2012-10-05"),
array(3, "2012-10-06"),
array(3, "2012-10-08"),
array(3, "2012-10-09"),
array(3, "2012-10-10")
);
$info = array();
foreach($dates as $roominfo) {
$time = strtotime($roominfo[1]);
$room = $roominfo[0];
if(!array_key_exists($roominfo[0], $info))
$info[$room] = array($time, $time);
if($time<$info[$room][0])
$info[$room][0] = $time;
if($time>$info[$room][1])
$info[$room][1] = $time;
}
foreach($info as $roomId => $roomRange) {
echo $roomId.' available from '.
date('d', $roomRange[0]).' - '.
date('d F Y', $roomRange[1]).' <br/>';
}
输出:
1 available from 07 - 10 October 2012
2 available from 07 - 10 October 2012
3 available from 05 - 10 October 2012
这并不完全符合您的要求,但我认为这应该足以达到您的目标。小心,房间不能在某个范围内一天可用,请记住这一点。