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

PHP
php 无限分类的实现
常用PHP代码
windows下安装配置php视频教程
MySQL数据库结构和数据的导出和导入
PHP实现 IP Whois 查询
PHP5 this,self和parent关键字详解
PHP 安全技巧连载 #1[译]
PHP 安全技巧连载 #2[译]
PHP 安全技巧连载 #3[译]
PHP 安全技巧连载 #4[译]
PHP 安全技巧连载 #5[译]
PHP 安全技巧连载 #6[译]
PHP 安全技巧连载 #7[译]
PHP 安全技巧连载 #8[译]
PHP 安全技巧连载 #9[译]
PHP 安全技巧连载 #10[译]
PHP 安全技巧连载 #11[译]
PHP error_reporting的使用
PHP 安全技巧连载 #12
使用PHP做Linux/Unix守护进程

PHP 中的 array_udiff_uassoc() 函数


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

Definition and Usage
定义和用法

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

Syntax
语法

array_udiff_uassoc(array1,array2,array3...,function1,function2)

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]
function1 Required. The name of the user-made function that compares the array keys
必要参数。指定在用户自定义函数中参与数组键比较的函数1[function1]的名称
function2 Required. The name of the user-made function that compares the array values
必要参数。指定在用户自定义函数中参与数组值比较的函数1[function1]的名称


Tips and Notes
提示和注意点

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

Note: For comparison, the key is used in the first function and the value is used in the second. They are both user-made functions.
注意:这里参与比较的是第一个函数中的键和第二个函数中的值。它们都是用户自定义函数。


Example
案例

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

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

Array ( [c] => Horse )

评论 (0) All

登陆 | 还没注册?