PHP array_udiff_uassoc()関数
例
2つの配列のキーと値を比較し(比較のために2つのユーザー定義関数を使用)、違いを返します。
<?php
function myfunction_key($a,$b)
{
if ($a===$b)
{
return 0;
}
return ($a>$b)?1:-1;
}
function myfunction_value($a,$b)
{
if ($a===$b)
{
return 0;
}
return ($a>$b)?1:-1;
}
$a1=array("a"=>"red","b"=>"green","c"=>"blue");
$a2=array("a"=>"red","b"=>"green","c"=>"green");
$result=array_udiff_uassoc($a1,$a2,"myfunction_value","myfunction_key");
print_r($result);
?>
定義と使用法
array_udiff_uassoc()関数は、2つ以上の配列のキーと値を比較し、その差を返します。
注:この関数は、比較のために2つのユーザー定義関数を使用します。キーは最初の関数で使用され、値は2番目の関数で使用されます。
この関数は、2つ(またはそれ以上)の配列のキーと値を比較し、 array2またはarray3などに存在しないarray1からのエントリを含む配列を返します。
構文
array_udiff_uassoc(array1, array2, array3, ..., myfunc_key, myfunc_value)
パラメータ値
Parameter | Description |
---|---|
array1 | Required. The array to compare from |
array2 | Required. An array to compare against |
array3,... | Optional. More arrays to compare against |
myfunc_key | Required. The name of the user-defined function that compares
the array keys. A string that define a callable comparison function. The comparison function must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument |
myfunc_value | Required. The name of the user-defined function that compares
the array values. A string that define a callable comparison function. The comparison function must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument. |
技術的な詳細
戻り値: | 他のどの配列にも存在しない array1からのエントリを含む配列を返します |
---|---|
PHPバージョン: | 5歳以上 |
❮PHP配列リファレンス