دالة PHP array_udiff_uassoc()
مثال
مقارنة اسم المفتاح وقيمة المفتاح في البنيات (استخدام دالة مستخدمة من قبل المستخدم للتحقق) وإرجاع الفرق:
<?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_udiff_uassoc($a1,$a2,"myfunction_key","myfunction_value"); print_r($result); ?>
التعريف والاستخدام
استخدمت دالة array_udiff_uassoc() لتحديد مقارنة بين اسم المفتاح وقيمة المفتاح في البنيات (أو أكثر) وإرجاع الفرق.
ملاحظة:استخدمت هذه الدالة دالتين مستخدمة من قبل المستخدم进行比较؛ الدالة الأولى مقارنة اسم المفتاح، والثانية مقارنة قيمة المفتاح!
يقارن هذه الدالة بين كلا (أو أكثر) من البنيات ويقوم بإرجاع بنية فرق، وتشمل هذه البنية جميع العناصر في البنيات المقارنة (array1)中,but not in any other parameter array(array2 or array3 etc.) Key names and key values.
شرح
يعود دالة array_udiff_uassoc() array1 جزء موجود في البنية ولكن غير موجود في البنيات الأخرى. البنية للناتج تحافظ على اسم المفتاح كما هو.
لاحظ مع array_diff() و array_udiff() الفرق هو أن اسم المفتاح أيضًا يستخدم للتحقق. يتم أيضًا مقارنة اسم المفتاح وقيمة المفتاح، مثل "a"=>1 و "b"=>1 هذان العنصران غير متساويين.
فحص اسم المفتاح (السلسلة) يتم أيضًا من خلال دالة الاستدعاء myfunction_key تم. هذا و array_udiff_assoc() The behavior is different, the latter uses internal functions to compare indices.
The comparison of array data is done using the callback function provided by the user myfunction_value is performed. In this aspect, and array_diff_assoc() The behavior is exactly opposite, the latter is compared by 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 elements in the compared arrays(array1)中,but not in any other parameter array(array2 or array3 etc.) Key names and key values. |
PHP Version: | 5+ |