توابع 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 the key name is also compared. Both key values and key names (indices) are compared by 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 compare 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.
Both key names and key values are compared at the same time, such as "a"=>1 and "b"=>1, these two elements are not equal.
myfunction_key These functions are used to compare whether the key names are equal.myfunction_value These functions are used to compare whether the key values are equal. Both functions have two parameters to be compared.
The key names in the returned array remain unchanged.
Technical Details
Return Value: | Returns an array containing all elements that array1 also in all other arrays. |
PHP Version: | 5+ |