Home  >  Article  >  php教程  >  array_intersect:根据值计算多个数组的交集

array_intersect:根据值计算多个数组的交集

PHP中文网
PHP中文网Original
2016-05-23 16:39:13976browse

array_intersect:根据值计算多个数组的交集

array array_intersect ( array $array1 , array $array2 [, array $ ... ] )
返回一个数组,该数组的值在每个数组都有

$arr1 = ['a'=>'aaa','b'=>'bbb','c'=>'ccc'];
$arr2 = ['bb'=>'ccc','dd'=>'aaa'];
$arr = array_intersect($arr1, $arr2);
 
echo &#39;<pre class="brush:php;toolbar:false">&#39;;
print_r($arr);
 
result:
Array
(
    [a] => aaa
    [c] => ccc
)

 以上就是array_intersect:根据值计算多个数组的交集的内容,更多相关内容请关注PHP中文网(www.php.cn)! 


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn