我有两个数组如下: -
$a = ["2","11","6"];
$b = ["6","7"];
$c = array_diff($a, $b);
$c = ["2","11"];
$c
中的结果是错误的。我希望结果应为$c = [6]
换句话说,我希望返回两个数组中的公共元素!但它给出了错误的错误。请帮助我?
答案 0 :(得分:2)
使用array_intersect()
$a = ["2","11","6"];
$b = ["6","7"];
$c = array_intersect($a, $b);
答案 1 :(得分:2)
您可以使用array_intersect
$c = array_intersect($a, $b);
答案 2 :(得分:2)
$a = ["2","11","6"];
$b = ["6","7"];
$c = array_intersect($a,$b);
答案 3 :(得分:0)
使用array_intersect(http://php.net/manual/en/function.array-intersect.php)
<?php
$a = ["2","11","6"];
$b = ["6","7"];
$c = array_intersect($a, $b);
print_r($c)
?>