当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > array_uintersect() 函数

PHP
WINDOWS下安装MySQL
PHP 制作 网站/服务器 监视脚本
用PHP和CSS制作活动按钮
PHP 单件模式
PHP MVC模式,类封装以及HACK
PHP 中使用正则表达式
PHP 防止 SQL 注入攻击
PHP 跨站点脚本攻击
PHP 防止用户操纵 GET 变量
PHP 防止远程表单提交

PHP 中的 array_uintersect() 函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 434 ::
收藏到网摘: n/a

Definition and Usage
定义和用法

The array_uintersect() function compares two or more arrays, in a user-made function, and returns an array containing the elements from the first array, if the user-made function allows it. The user-made function compares array values, and returns a numeric value, 0 if the returned array should contain this element.
array_uintersect()函数通过比较用户自定义函数中的两个或多个数组,找出其中相同的元素,并返回位于第一个数组中相同的元素;如果返回值设置为“return 1”,则表示返回的数组中需要包含上述那个位于第一个数组中相同的元素;如果设置为“return 0[或者是一个负数,如:-1]” ,则表示不包含该元素。

Syntax
语法

array_uintersect(array1,array2,array3...,function)

Parameter参数 Description描述
array1 Required. The first array is the array that the others will be compared with
必要参数。指定一个参与比较的基准数组
array2 Required. An array to be compared with the first array
必要参数。与数组1[array1]进行比较的数组2[array2]
array3 Optional. An array to be compared with the first array
可选参数。与数组1[array1]进行比较的数组3[array3]
function Required. The name of the user-made function
必要参数。用户自定义函数的名称


Tips and Notes
提示和注意点

Tip: You can compare the first array with one array, or as many as you like.
提示:你可以使用一个或多个数组与数组1[array1]进行比较。

Note: Only the value is used in the comparison.
注意:该函数仅对数组中的值进行比较。


Example
案例

<?php
function myfunction($v1,$v2)
{
if ($v1===$v2)	{	return 0;	}
return 1;
}
$a1=array("a"=>"Cat","b"=>"Dog","c"=>"Horse");
$a2=array(1=>"Cat",2=>"Dog",3=>"Fish");
print_r(array_uintersect($a1,$a2,"myfunction"));
?>

The output of the code above will be:
上述代码将输出下面的结果:

Array ( [a] => Cat [b] => Dog )

评论 (0) All

登陆 | 还没注册?