我有一个数组的数组。还有另一个数组的数组。如果存在一个具有 common 值的数组,我希望将其从第一个数组中删除:这是我的代码
function availableTables($tables, $tablesWithDate) {
$tablesReturn = array();
foreach($tables as $table) {
foreach($tablesWithDate as $twd) {
if($table['table_no'] == $twd['number']){
echo "true";
} else {
echo "false";
}
}
}
return $tablesReturn;
}
这样,除了 2 次返回 true 之外,每次迭代的输出都是 false。这是正确的,但我想从第一个数组中删除它们。我努力了:
function availableTables($tables, $tablesWithDate) {
$tablesReturn = array();
foreach($tables as $table) {
foreach($tablesWithDate as $twd) {
if($table['table_no'] == $twd['number']){
unset($table);
} else {
echo "false";
}
}
}
return $tablesReturn;
}
但不起作用。它说未定义的变量表。我也尝试过unset($tables[$table])
$TablesWithDate:
Array
(
[0] => Array
(
[id] => 206
[number] => 150
[capacity] => 4
[booking_code] => qhJEHcWnzty062DD
[reservation_date] => 2020-07-09 01:00:00
[start_time] => 12:30:00.000000
[end_time] => 14:15:00.000000
)
[1] => Array
(
[id] => 206
[number] => 150
[capacity] => 4
[booking_code] => ym9dP1aZtFstP3WM
[reservation_date] => 2020-07-22 01:00:00
[start_time] => 20:00:00.000000
[end_time] => 21:45:00.000000
)
)
表:
(
[0] => Array
(
[id] => 159
[table_no] => 150
[capacity] => 6
[shape] => large_rectangle
[joinable] => 1
[area] => 1
[baby_friendly] => 1
[premise_code] => LJJIDHhRN2ho1e3h
[area_name] => Ferkin
[premise_name] => An Poitin Stil
)
LEATH