PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<array_fliparray_intersect_key>
Last updated: Mon, 16 Jul 2012

array_intersect_assoc

(PHP 4 >= 4.3.0, PHP 5)

array_intersect_assoc -- 带索引检查计算数组的交集

说明

array array_intersect_assoc ( array array1, array array2 [, array ...] )

array_intersect_assoc() 返回一个数组,该数组包含了所有在 array1 中也同时出现在所有其它参数数组中的值。注意和 array__intersect() 不同的是键名也用于比较。

例子 1. array_intersect_assoc() 例子

<?php
$array1
= array ("a" => "green", "b" => "brown", "c" => "blue", "red");
$array2 = array ("a" => "green", "yellow", "red");
$result_array = array_intersect_assoc($array1, $array2);

/* $result_array will look like:

Array
(
   [a] => green
)

*/
?>

上面例子中可以看到只有键值对 "a" => "green" 在两个数组中都存在从而被返回。值 "red" 没有被返回是因为在 $array1 中它的键名是 0 而在 $array2"red" 的键名是 1

键值对 key => value 中的两个值仅在 (string) $elem1 === (string) $elem2 时被认为相等。也就是说使用了严格检查,字符串的表达必须相同。

参见 array_intersect()array_diff()array_diff_assoc()




<array_fliparray_intersect_key>
 Last updated: Mon, 16 Jul 2012
 
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: http://manual.phpv.net/
Last updated: Thu Jul 7 19:13:47 2005 CST