我有一个为过去 7 天生成时间戳的数组,我有一个 2d 数组,它为过去 7 天内的某些天提供一个值。我想使用第一个数组来填充每个键下不存在值的天数。
$酒店数据:
Array
(
[49] => Array
(
[1365202800] => 2
)
[48] => Array
(
)
[50] => Array
(
[1364943600] => 4
[1365375600] => 5
)
)
$d:
Array
(
[1365375600] => 0
[1365289200] => 0
[1365202800] => 0
[1365116400] => 0
[1365030000] => 0
[1364943600] => 0
[1364857200] => 0
[1364770800] => 0
[1364688000] => 0
[1364601600] => 0
)
这是我试图用来合并两个数组的代码:
foreach($hotel_data as $key1=>$value1) {
foreach($hotel_data[$key1] as $datekey=>$ratingval) {
foreach($d as $key2=>$value2)
{
if($datekey !== $key2) {
$hotel_data[$key1][$key2] = 0;
}
}
//echo $datekey.'<br/>';
}
}
这是结果:
Array
(
[49] => Array
(
[1365202800] => 2
[1365375600] => 0
[1365289200] => 0
[1365116400] => 0
[1365030000] => 0
[1364943600] => 0
[1364857200] => 0
[1364770800] => 0
[1364688000] => 0
[1364601600] => 0
)
[48] => Array
(
)
[50] => Array
(
[1364943600] => 0
[1365375600] => 0
[1365289200] => 0
[1365202800] => 0
[1365116400] => 0
[1365030000] => 0
[1364857200] => 0
[1364770800] => 0
[1364688000] => 0
[1364601600] => 0
)
)
但正如你所看到的,由于某种原因,[49] 的值仍然存在,但 [50] 中的两个值已被 0 替换。