توابع array_udiff_assoc() در PHP
مثال
مقایسه کلیدها و مقدارهای دو آرایه (از توابع داخلی برای مقایسه کلیدها استفاده میشود و از توابع کاربر تعریف شده برای مقایسه مقدارها استفاده میشود) و تفاوت بازمیگردانند:
<?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); ?>
تعریف و استفاده
توابع array_udiff() برای مقایسه دو (یا بیشتر از دو) آرایههای کلید و مقدار استفاده میشوند و یک تفاوت بازمیگردانند.
نکته:این توابع از توابع داخلی برای مقایسه کلیدها استفاده میکنند و از توابع کاربر تعریف شده برای مقایسه مقدارها استفاده میکنند.
این توابع دو (یا بیشتر از دو) آرایههای کلید و مقدار را مقایسه میکنند و یک آرایه تفاوت بازمیگردانند، این آرایه شامل تمامی عناصر است که در آرایههای مقایسه شده وجود دارند (array1in, but not in any other parameter array (array2 or array3 etc.) Key names and key values.
توضیح
توابع array_udiff_assoc() بازمیگردد array1 بخشی که در یک آرایه وجود دارد اما در سایر آرایهها وجود ندارد.
注意与 array_diff() Notice the difference with array_diff() and
array_udiff() Array data comparison is done using the callback function provided by the user. In this respect, it is different from array_diff_assoc()
The behavior of array_udiff_assoc() function is exactly opposite, the latter is compared using the internal function. 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 returns 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, defining 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 (array1in, but not in any other parameter array (array2 or array3 etc.) Key names and key values. |
PHP Version: | 5+ |