0
給定兩個數組:查找陣列匹配和刪除元素
$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?
}
}
?>
你可以使用未設置(陣列(索引)); http://in2.php.net/unset –
內置函數:'array_diff' http://php.net/array_diff – Fracsi