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

PHP
PHP 安全邮件
MySQL 介绍
连接 MySQL
创建 MySQL
MySQL 插入记录
MySQL 选择记录
MySQL Where
MySQL Order By
MySQL 记录更新
MySQL 删除记录
PHP ODBC
XML Expat Parser
XML SimpleXML
PHP 数组参考
PHP Calendar
PHP Date
PHP Directory
PHP Filesystem
PHP FTP
PHP HTTP

PHP 中的 array_udiff_uassoc() 函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 529 ::
收藏到网摘: 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

登陆 | 还没注册?