array_intersect_assoc 带索引检查计算数组的交集 &reftitle.description; arrayarray_intersect_assoc arrayarray1 arrayarray2 array ... array_intersect_assoc 返回一个数组,该数组包含了所有在 array1 中也同时出现在所有其它参数数组中的值。注意和 array_intersect 不同的是键名也用于比较。 &reftitle.parameters; array1 The array with master values to check. array2 An array to compare values against. array 要对比的数组变量的列表。 &reftitle.returnvalues; 返回一个数组,该数组包含了所有在 array1 中也同时出现在所有其它参数数组中的值。 &reftitle.examples; <function>array_intersect_assoc</function> 例子 "green", "b" => "brown", "c" => "blue", "red"); $array2 = array("a" => "green", "b" => "yellow", "blue", "red"); $result_array = array_intersect_assoc($array1, $array2); print_r($result_array); ?> ]]> &example.outputs; green ) ]]> 上面例子中可以看到只有键值对 "a" => "green" 在两个数组中都存在从而被返回。值 "red" 没有被返回是因为在 $array1 中它的键名是 0 而在 $array2"red" 的键名是 1,键 "b" 没有返回的原因是它的值和其他数组不同。 键值对 key => value 中的两个值仅在 (string) $elem1 === (string) $elem2 时被认为相等。也就是说使用了严格检查,字符串的表达必须相同。 &reftitle.seealso; array_intersect array_uintersect_assoc array_intersect_uassoc array_uintersect_uassoc array_diff array_diff_assoc