PHP array_udiff_assoc() Funktion
Beispiel
Vergleiche die Schlüsselnamen und -werte von zwei Arrays (verwende interne Funktionen zum Vergleich der Schlüsselnamen und benutzerdefinierte Funktionen zum Vergleich der Schlüsselwerte) und gibt die Differenzmaske zurück:
<?php function myfunction($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"=>"blue","c"=>"green"); $result=array_udiff_assoc($a1,$a2,"myfunction"); print_r($result); ?>
Definition und Verwendung
Die Funktion array_udiff() wird verwendet, um die Schlüsselnamen und -werte von zwei (oder mehr) Arrays zu vergleichen und eine Differenzmaske zurückzugeben.
Anmerkung:Diese Funktion verwendet interne Funktionen, um die Schlüsselnamen zu vergleichen, und benutzerdefinierte Funktionen, um die Schlüsselwerte zu vergleichen.
Diese Funktion vergleicht die Schlüsselnamen und -werte von zwei (oder mehr) Arrays und gibt eine Differenzmaske zurück, die alle Elemente enthält, die in den verglichenen Arraysarray1)中,但是不在任何其他参数数组(array2 or array3 etc.) Key names and values.
Erklärung
Die Funktion array_udiff_assoc() gibt zurück array1 Die Teile, die in der einen, aber nicht in den anderen Arrays vorhanden sind.
注意与 array_diff() and array_udiff() the difference is that the key name is also used for comparison. The comparison of both key names and values is performed simultaneously. For example, the elements "a"=>1 and "b"=>1 are not equal.
The comparison of array data is done using the callback function provided by the user. In this regard, and array_diff_assoc() behavior is exactly the opposite, the latter is compared with the internal function.
array_udiff_assoc() function's myfunction The function specified by the parameter is used to compare whether elements are equal.myfunction The function has two parameters to be compared. If the first parameter is less than the second parameter, the function returns a negative number, if the two parameters are equal, it should return 0, and if the first parameter is greater than the second, it returns a positive number.
Syntax
array_udiff_assoc(array1,array2,array3...myfunction)
Parameters | Description |
---|---|
array1 | Required. The first array to be compared with other arrays. |
array2 | Required. The array to be compared with the first array. |
array3,... | Optional. Other arrays to compare with the first array. |
myfunction |
Required. String value, defines the callable comparison function. If the first parameter is less than or equal to or greater than the second parameter, the comparison function must return an integer less than or equal to or greater than 0. |
Technical Details
Return Value: | Returns the difference set array, which includes all elements in the compared arrays(array1)中,但是不在任何其他参数数组(array2 or array3 etc.) Key names and values. |
PHP Version: | 5+ |