Array#1
Array(
[0] => Array(
[id] => 0
[name] => a
)
[1] => Array(
[id] => 1
[name] => b
)
[2] => Array(
[id] => 2
[name] => c
)
)
Array #2
Array(
[0] => Array(
[id] => 0
[name] => c
)
[1] => Array(
[id] => 1
[name] => a
)
)
我想取消第一个数组,第二个数组引用名称,因为键一直在变化。
我坚持使用循环删除名称而不是密钥。非常感谢任何帮助!
我想删除阵列#1中的#2阵列。
Final Array
Array(
[0] => Array(
[id] => 1
[name] => b
)
}
答案 0 :(得分:2)
$arr = Array(
0 => array(
'id' => 0,
'name' => 'a'),
1 => array(
'id' => 1,
'name' => 'b'),
2 => array(
'id' => 2,
'name' => 'c'));
$arr2 = Array(
0 => array(
'id' => 0,
'name' => 'c'),
1 => array(
'id' => 1,
'name' => 'a'));
$ex = array_map(function($a) {return $a['name'];}, $arr2);
foreach ($arr as $key => $value){
if (in_array($value['name'], $ex)){
unset($arr[$key]);
}
}
print_r($arr);
输出:
Array
(
[1] => Array
(
[id] => 1
[name] => b
)
)