给出两个数组:
$arr1 = (1, 0, 9);
$arr2 = (8, 0, 2, 9, 4);
如何删除$arr2
中包含的$arr1
中的元素?
这将返回$arr3 = (8, 2, 4);
我试过这个:
<?php
foreach($arr1 as $item)
{
if(in_array($item, $arr2))
{
# This is were I lose it, I've found a match then what?
}
}
?>
答案 0 :(得分:1)
array_diff
正是您要找的
看看here
$arr1 = array(1, 0, 9);
$arr2 = array(8, 0, 2, 9, 4);
echo print_r(array_diff($arr2,$arr1),true);
>> Array ( [0] => 8 [2] => 2 [4] => 4 )