PHP array_udiff_uassoc ()ฟังก์ชั่น
ตัวอย่าง
เปรียบเทียบคีย์และค่าของสองอาร์เรย์ (โดยใช้ฟังก์ชันที่ผู้ใช้กำหนดเอง 2 ฟังก์ชันเพื่อเปรียบเทียบ) และคืนค่าความแตกต่าง:
<?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_value","myfunction_key");
print_r($result);
?>
ความหมายและการใช้งาน
ฟังก์ชัน array_udiff_uassoc() จะเปรียบเทียบคีย์และค่าของอาร์เรย์ตั้งแต่สองตัวขึ้นไป และคืนค่าความแตกต่าง
หมายเหตุ:ฟังก์ชันนี้ใช้ฟังก์ชัน ที่ผู้ใช้กำหนด สองฟังก์ชันสำหรับการเปรียบเทียบ คีย์ถูกใช้ในฟังก์ชันแรก และใช้ค่าในฟังก์ชันที่สอง!
ฟังก์ชันนี้เปรียบเทียบคีย์และค่าของอาร์เรย์สอง (หรือมากกว่า) และส่งคืนอาร์เรย์ที่มีรายการจากarray1ที่ไม่มีอยู่ในarray2หรือarray3เป็นต้น
ไวยากรณ์
array_udiff_uassoc(array1, array2, array3, ..., myfunc_key, myfunc_value)
ค่าพารามิเตอร์
Parameter | Description |
---|---|
array1 | Required. The array to compare from |
array2 | Required. An array to compare against |
array3,... | Optional. More arrays to compare against |
myfunc_key | Required. The name of the user-defined function that compares
the array keys. A string that define a callable comparison function. The comparison function must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument |
myfunc_value | Required. The name of the user-defined function that compares
the array values. A string that define a callable comparison function. The comparison function must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument. |
รายละเอียดทางเทคนิค
คืนมูลค่า: | ส่งกลับอาร์เรย์ที่มีรายการจาก array1ที่ไม่มีอยู่ในอาร์เรย์อื่น ๆ |
---|---|
รุ่น PHP: | 5+ |
❮ การอ้างอิงอาร์เรย์ PHP