Προτεινόμενες ενότητες
PHP array_udiff_uassoc() συνάρτηση
Παράδειγμα
Σύγκριση των ονομάτων κλειδιών και των τιμών δύο πινάκων (χρησιμοποιώντας χρήσιμες συναρτήσεις για σύγκριση) και επιστροφή διαφοράς: <?php if ($a===$b) function myfunction_value($a,$b) if ($a===$b) { return ($a>$b)?1:-1; return 0; return ($a>$b)?1:-1; function myfunction_key($a,$b) if ($a===$b) function myfunction_value($a,$b) if ($a===$b) { return ($a>$b)?1:-1; 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_key","myfunction_value") ; print_r($result);
Δημιουργία παραδείγματος
Ορισμός και χρήση
Η συνάρτηση array_udiff_uassoc() χρησιμοποιείται για σύγκριση δύο (ή περισσότερων) πινάκων ονομάτων κλειδιών και τιμών, και επιστρέφει διαφορά.Σημείωση:
Η συνάρτηση αυτή χρησιμοποιεί δύο χρήσιμες συνάρτησεις για σύγκριση; Η πρώτη συνάρτηση συγκρίνει τα ονόματα κλειδιών, η δεύτερη συνάρτηση συγκρίνει τις τιμές!array1but not in any other parameter array (array2 or array3 etc.) key names and values.
Η συνάρτηση αυτή συγκρίνει δύο (ή περισσότερους) πίνακες ονομάτων κλειδιών και τιμών, και επιστρέφει έναν πίνακα διαφοράς που περιλαμβάνει όλους τους πίνακες που συγκρίνονται (
Επεξηγήσεις array1 Η συνάρτηση array_udiff_uassoc() επιστρέφει
Λάβετε υπόψη ότι υπάρχει στον πίνακα αλλά δεν υπάρχει σε άλλους πίνακες. Ο πίνακας που επιστρέφεται διατηρεί τα ονόματα κλειδιών όπως είναι. array_diff() και array_udiff() Η διαφορά είναι ότι το όνομα κλειδιού χρησιμοποιείται επίσης για σύγκριση. Σε παράλληλη σύγκριση του ονόματος κλειδιού και της τιμής του, όπως τα "a"=>1 και "b"=>1, αυτές οι δύο μονάδες δεν είναι ισότιμες.
Η έλεγχος του ονόματος κλειδιού (ιδίου) γίνεται από την ανατροφοδότηση της συνάρτησης myfunction_key Η διαδικασία είναι. Αυτό και array_udiff_assoc() acts differently, the latter compares the indices using internal functions.
array data comparison is performed using the callback function provided by the user myfunction_value is performed. In this respect, and array_diff_assoc() acts exactly the opposite, the latter is compared using internal functions.
Both functions have 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, then return 0, if the first parameter is greater than the second, then return a positive number.
Syntax
array_udiff_uassoc(array1,array2,array3...myfunction_key,myfunction_value)
Parameters | Description |
---|---|
array1 | Required. The first array to compare with other arrays. |
array2 | Required. The array to compare with the first array. |
array3,... | Optional. Other arrays to compare with the first array. |
myfunction_key |
Required. The name of the user-defined function used to compare array keys. String values, defining the callable comparison function. If the first parameter is less than, equal to, or greater than the second parameter, the comparison function must return an integer less than, equal to, or greater than 0. |
myfunction_value |
Required. The name of the user-defined function used to compare array values. String values, defining the callable comparison function. If the first parameter is less than, equal to, or greater than the second parameter, the comparison function must return an integer less than, equal to, or greater than 0. |
Technical Details
Return Value: | Returns the difference set array, which includes all the elements that are in all the compared arrays (array1but not in any other parameter array (array2 or array3 etc.) key names and values. |
PHP Version: | 5+ |