超越PHP PHP动态 | 经典文章 | CLASS | 相关下载 | 常见问题 | FORUM | WIKI | 在线手册
Site search:    
<array_intersect_ukeyarray_key_exists>
Last updated: Fri, 22 Jun 2007

array_intersect

(PHP 4 >= 4.0.1, PHP 5)

array_intersect -- 计算数组的交集

说明

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

array_intersect() 返回一个数组,该数组包含了所有在 array1 中也同时出现在所有其它参数数组中的值。注意键名保留不变。

例子 1. array_intersect() 例子

<?php
$array1
= array ("a" => "green", "red", "blue");
$array2 = array ("b" => "green", "yellow", "red");
$result = array_intersect ($array1, $array2);
?>

这使得 $result 成为:

Array
(
   [a] => green
   [0] => red
)

注: 两个单元仅在 (string) $elem1 === (string) $elem2 时被认为是相同的。也就是说,当字符串的表达是一样的时候。

参见 array_intersect_assoc()array_diff()array_diff_assoc()




add a note add a note User Contributed Notes
array_intersect
david at audiogalaxy dot com
10-Apr-2001 07:54
Note that array_intersect() considers the type of the array elements when it compares them.

If array_intersect() doesn't appear to be working, check your inputs using var_dump() to make sure you're not trying to intersect an array of integers with an array of strings.

<array_intersect_ukeyarray_key_exists>
 Last updated: Fri, 22 Jun 2007
view source | feedback | send page | sitemap | aboutus   
Copyright ® 2002-2003 PHPE.NET. All rights reserved
Last updated:2002-11-22