Home >Backend Development >PHP Tutorial >php array_intersect()函数使用代码_PHP

php array_intersect()函数使用代码_PHP

WBOY
WBOYOriginal
2016-06-01 12:23:29880browse

array array_intersect ( array array1, array array2 [, array ...])
array_intersect() 函数返回两个或多个数组的交集数组。
array_intersect() 返回一个数组,该数组包含了所有在 array1 中也同时出现在所有其它参数数组中的值。注意键名保留不变。
下面就拿手册上的例子给大家演示:


$array1 = array ("a" => "green", "red", "blue");
$array2 = array ("b" => "green", "yellow", "red");
$result = array_intersect ($array1, $array2);
print_r($result);
?>
输出结果如下:

Array
(
[a] => green
[0] => red
)

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