Array ( [0] => Array ( [key1] => value1 [key2] => value2 ) [1] => Array ( [key1] => value3 [key2] => value4 ) [2] => Array ( [key1] => value5 [key2] => value6 ) [3] => Array ( [key1] => value7 [key2] => value9 ) [4] => Array ( [key1] => value11 [key2] => value13 ))
第二个数组如下:
Array ( [0] => value1 [1] => value3 [2] => value9)
因此,我需要解析第一个数组中的所有值,并将第一个键与第二个数组中的元素进行比较。 像这样的东西
foreach($array1 as $ar1){
foreach($array2 as $ar2){
if($ar1['key1'] == $ar2){
unset($array1[$ar1]);
}
}
}
我已经尝试了一切,但它没有用。生成第一个数组,因此我无法更改其结构。第二个是手工制作的。 在该过程之后,第一个数组将如下所示:
Array ([2] => Array ( [key1] => value5 [key2] => value6 ) [3] => Array ( [key1] => value7 [key2] => value8 ))
帮助我一些想法。 感谢
答案 0 :(得分:0)
试试这个:
foreach($array1 as $k => $ar1){
foreach($array2 as $ar2){
if($ar1['key1'] == $ar2){
unset($array1[$k]);
}
}
}