Funkce PHP array_udiff_uassoc().
Příklad
Porovnejte klíče a hodnoty dvou polí (pro porovnání použijte dvě uživatelsky definované funkce) a vraťte rozdíly:
<?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);
?>
Definice a použití
Funkce array_udiff_uassoc() porovnává klíče a hodnoty dvou nebo více polí a vrací rozdíly.
Poznámka: Tato funkce používá pro porovnání dvě uživatelsky definované funkce; klíč je použit v první funkci a hodnota je použita ve druhé!
Tato funkce porovná klíče a hodnoty dvou (nebo více) polí a vrátí pole, které obsahuje položky z pole1 , které nejsou přítomny v poli2 nebo pole3 atd.
Syntax
array_udiff_uassoc(array1, array2, array3, ..., myfunc_key, myfunc_value)
Hodnoty parametrů
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. |
Technické údaje
Návratová hodnota: | Vrátí pole obsahující položky z pole1 , které nejsou přítomny v žádném jiném poli |
---|---|
Verze PHP: | 5+ |
❮ PHP Array Reference