$a1=array("a"=>"red","b"=>"green","c"=>"blue"); $a2=array("a"=>"red","c"=>"blue","d"=>"pink"); $result = array_intersect_key($a1,$a2); print_r($result);
Array ( [a] => red [c] => blue )
$mid_arr = [2,3];
$area_mids = [20,30];
$mid_arr = array_intersect($mid_arr,$area_mids); // 返回2集合的交集
dump($mid_arr);
exit;
<pre>array(0) {
}
</pre>
$mid_arr = [2,3];
$area_mids = [20,30];
$mid_arr_2 = array_intersect_key($mid_arr,$area_mids); // 第二个集合和第一个集合相比, 从第一个集合中砍掉,2个集合的交集
dump($mid_arr_2);
exit;
<pre>array(2) {
[0] => int(2)
[1] => int(3)
}
</pre>
比较两个数组的键名,并返回交集:array_intersect_key
原文:https://www.cnblogs.com/pansidong/p/11587489.html