PHP array_udiff_uassoc() Funzione
Esempio
Confronta le chiavi e i valori di due array (utilizzando due funzioni definite dall'utente per il confronto) e restituisce le differenze:
<?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);
?>
Definizione e utilizzo
La funzione array_udiff_uassoc() confronta le chiavi ei valori di due o più array e restituisce le differenze.
Nota: questa funzione utilizza due funzioni definite dall'utente per il confronto; la chiave viene utilizzata nella prima funzione e il valore nella seconda!
Questa funzione confronta le chiavi e i valori di due (o più) array e restituisce un array che contiene le voci di array1 che non sono presenti in array2 o array3, ecc.
Sintassi
array_udiff_uassoc(array1, array2, array3, ..., myfunc_key, myfunc_value)
Valori dei parametri
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. |
Dettagli tecnici
Valore di ritorno: | Restituisce una matrice contenente le voci di matrice1 che non sono presenti in nessuna delle altre matrici |
---|---|
Versione PHP: | 5+ |
❮ Riferimento all'array PHP