比较值两个数组,并返回匹配项:
<?php
$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$a2=array("e"=>"red","f"=>"green","g"=>"blue");
$result=array_intersect($a1,$a2);
print_r($result);
?>
亲自试一试 »
array_intersect() 函数比较值两个(或多个)数组,并返回匹配项。
此函数比较两个或多个数组的值,并返回一个包含以下条目的数组数组1存在于数组2,数组3, ETC。
array_intersect(
array1, array2, array3, ...)
Parameter | Description |
---|---|
array1 | Required. The array to compare from |
array2 | Required. An array to compare against |
array3,... | Optional. More arrays to compare against |
返回值: | 返回一个包含条目的数组数组1存在于所有其他数组中 |
---|---|
PHP 版本: | 4.0.1+ |
比较值三个数组,并返回匹配项:
<?php
$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$a2=array("e"=>"red","f"=>"black","g"=>"purple");
$a3=array("a"=>"red","b"=>"black","h"=>"yellow");
$result=array_intersect($a1,$a2,$a3);
print_r($result);
?>
亲自试一试 »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!