我有一個合適的預訂時間數組和另一個多維數組,其中包含每個日期已經預訂的時間數組。我想迭代每個日期併爲每個日期構建另一個單獨的多維數組,這些日期包含第一個數組中可自由訂閱的時間。PHP多維數組根據索引數組比較並刪除值
$times = array("9:00", "10:00", "11:00", "12:00", "13:00");
$dates = array(
"28/07/2018" => array("10:00", "11:00"),
"29/07/2018" => array("10:00", "13:00"),
"30/07/2018" => array("11:00", "13:00"));
// function to remove duplicates
function myArrayDiff($array1, $array2) {
// loop through each item on the first array
foreach ($array1 as $key => $row) {
// loop through array 2 and compare
foreach ($array2 as $key2) {
if ($row['id'] == $key2) {
// if we found a match unset and break out of the loop
unset($array2[$key2]);
break;
}
}
}
return array_values($array2);
}
$array3 = myArrayDiff($dates, $times);
print_r($array3);
究竟是什麼問題,你需要幫助?它不清楚你的問題。 – FluffyKitten
當你有一個縮進的代碼塊時,不需要用反引號('\'')把它括起來。事實上,反引號包含在你的代碼塊中,並且可以輕鬆搞定語法突出顯示。 – Chris