目录

PHP array_intersect_assoc() 函数

❮ PHP 数组参考

示例

比较键和值两个数组,并返回匹配项:

<?php
$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$a2=array("a"=>"red","b"=>"green","c"=>"blue");

$result=array_intersect_assoc($a1,$a2);
print_r($result);
?>
亲自试一试 »

定义和用法

array_intersect_assoc() 函数比较键和值两个(或多个)数组,并返回匹配项。

此函数比较两个或多个数组的键和值,并返回一个包含以下条目的数组数组1存在于数组2,数组3, ETC。


语法

array_intersect_assoc( array1,array2,array3, ...)

参数值

Parameter Description
array1 Required. The first array is the array that the others will be compared with
array2 Required. An array to be compared with the first array
array3,... Optional. An array to be compared with the first array

技术细节

返回值: 返回一个包含条目的数组数组1存在于所有其他数组中
PHP 版本: 4.3.0+

更多示例

示例

比较键和值三个数组,并返回匹配项:

<?php
$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$a2=array("a"=>"red","b"=>"green","g"=>"blue");
$a3=array("a"=>"red","b"=>"green","g"=>"blue");

$result=array_intersect_assoc($a1,$a2,$a3);
print_r($result);
?>
亲自试一试 »

❮ PHP 数组参考