阵列交集
array_intersect
函数将返回存在于传递给此函数的所有数组中的值数组。
$array_one = ['one', 'two', 'three'];
$array_two = ['two', 'three', 'four'];
$array_three = ['two', 'three'];
$intersect = array_intersect($array_one, $array_two, $array_three);
// $intersect contains ['two', 'three']
数组键被保留。原始数组的索引不是。
array_intersect
只检查数组的值。array_intersect_assoc
函数将返回数组与键的交集。
$array_one = [1 => 'one',2 => 'two',3 => 'three'];
$array_two = [1 => 'one', 2 => 'two', 3 => 'two', 4 => 'three'];
$array_three = [1 => 'one', 2 => 'two'];
$intersect = array_intersect_assoc($array_one, $array_two, $array_three);
// $intersect contains [1 =>'one',2 => 'two']
array_intersect_key
功能只检查键的交叉点。它将返回所有数组中存在的键。
$array_one = [1 => 'one',2 => 'two',3 => 'three'];
$array_two = [1 => 'one', 2 => 'two', 3 => 'four'];
$array_three = [1 => 'one', 3 => 'five'];
$intersect = array_intersect_key($array_one, $array_two, $array_three);
// $intersect contains [1 =>'one',3 => 'three']