Συνάρτηση array_uintersect_uassoc() του PHP
Παράδειγμα
Σύγκριση των κλειδιών και των τιμών δύο συνόλων (χρησιμοποιώντας προσαρμοσμένες συναρτήσεις για σύγκριση) και επιστροφή της διασταυρούμενης ενότητας (ταιριάζοντα):
<?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_uintersect_uassoc($a1,$a2,"myfunction_key","myfunction_value"); print_r($result); ?>
Ορισμός και χρήση
Η συνάρτηση array_uintersect_uassoc() συγκρίνει δύο (ή περισσότερους) δείκτες κλειδιών και τιμών και επιστρέφει την διασταυρούμενη ενότητα.
Σημείωση:Η συνάρτηση αυτή χρησιμοποιεί δύο χρήσιμες συναρτήσεις για σύγκριση; Η πρώτη συγκρίνει τα κλειδιά, η δεύτερη συγκρίνει τις τιμές!
Η συνάρτηση αυτή συγκρίνει δύο (ή περισσότερους) δείκτες κλειδιών και τιμών και επιστρέφει ένα σύνολο διασταυρούμενης ενότητας, το οποίο περιλαμβάνει όλους τους δείκτες που συγκρίνονται στις συγκριθείσες σειρές (array1επίσης σε οποιοδήποτε άλλο σύνολο παραμέτρων (array2 ή array3 κλειδιά και τιμές.
Σημείωση, με array_uintersect() The difference is that key names also need to be compared. Both key values and key names (indices) are compared using callback functions.
Syntax
array_uintersect_uassoc(array1,array2,array3...myfunction_key,myfunction_value)
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 be compared with the first array. |
myfunction_key |
Required. The name of the user-defined function used to compare array key names. Define a 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 key values. Define a 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. |
Use a user-defined callback function myfunction_key and myfunction_value to calculate the intersection of two or more arrays (i.e., array1 that exist in both the array and in any other array), and return the resulting array.
Simultaneously compare key names and key values, such as "a"=>1 and "b"=>1, these two elements are not equal.
myfunction_key The specified function is used to compare whether the key names are equal.myfunction_value The specified function is used to compare whether the key values are equal. Both functions have two parameters to be compared. If the first parameter is less than the second, the function returns a negative number; if the two parameters are equal, it returns 0; if the first parameter is greater than the second, it returns a positive number.
The array returned keeps the original key names unchanged.
Technical Details
Return Value: | Returns an array containing all the elements that exist in array1 also in all other arrays. |
PHP Version: | 5+ |