我有一个数组的数组。还有另一个数组的数组。如果存在一个具有 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 )
1 回答
LEATH
TA贡献1936条经验 获得超6个赞
使用表数组的索引(代码中的$key)并使用 取消设置unset($tables[$key]。
function availableTables($tables, $tablesWithDate) {
$tablesReturn = array();
foreach($tables as $key => $table) {
foreach($tablesWithDate as $twd) {
if($table['table_no'] == $twd['number']){
unset($tables[$key]);
} else {
echo "false";
}
}
}
return $tables;
}
- 1 回答
- 0 关注
- 148 浏览
添加回答
举报
0/150
提交
取消