PHP 中的 array_intersect_assoc() 函数
phpprogrammingserver side programming更新于 2025/9/20 11:52:00
array_intersect_assoc() 函数比较数组值,并返回匹配项。
语法
array_intersect_assoc(arr1, arr2, arr3, arr4, …)
参数
arr1 − 要比较的数组。必填项。
arr2 − 要比较的数组。必填项。
arr3 − 您可以添加更多数组进行比较。可选。
arr4 − 您可以添加更多数组进行比较。可选。
返回
array_intersect_assoc() 函数返回一个数组,其中包含第一个数组中的所有值,该数组的值存在于所有参数中。
示例
<?php
$arr1 = array("p"=>"headphone","q"=>"earpod","r"=>"charger");
$arr2 = array("p"=>"headphone","q"=>"earpod");
$res = array_intersect_assoc($arr1,$arr2);
print_r($res);
?>
输出
Array ( [p] => headphone [q] => earpod )

