好的,两个阵列:
$first = array(1,2,3,4,5,6,7,8,9,10);
$second = array(1,2,3,4,5);
在执行array_merge样式函数时,是否有一种方法(如果可以帮助则不通过它们循环),它返回此数组:
$new = array(6,7,8,9,10);
如果找到匹配,则不返回。
答案 0 :(得分:7)
请参阅array_diff()
$new = array_diff($first, $second);
print_r($new);
/*
Array
(
[5] => 6
[6] => 7
[7] => 8
[8] => 9
[9] => 10
)
*/
答案 1 :(得分:2)
array_diff()
应该这样做:
<?php
$array1 = array("a" => "green", "red", "blue", "red");
$array2 = array("b" => "green", "yellow", "red");
$result = array_diff($array1, $array2);
print_r($result);
?>
Array
(
[1] => blue
)
答案 2 :(得分:1)
答案 3 :(得分:0)
答案 4 :(得分:0)
试试这个:
$new = array_diff($first , $second );