Hàm array_uintersect_uassoc () trong PHP
Thí dụ
So sánh các khóa và giá trị của hai mảng (sử dụng hai hàm do người dùng xác định để so sánh) và trả về các kết quả phù hợp:
<?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);
?>
Định nghĩa và Cách sử dụng
Hàm array_uintersect_uassoc () so sánh các khóa và giá trị của hai hoặc nhiều mảng và trả về các kết quả phù hợp.
Lưu ý: Hàm này sử dụng hai hàm do người dùng định nghĩa để so sánh; khóa được sử dụng trong chức năng đầu tiên và giá trị được sử dụng trong chức năng thứ hai!
Hàm này so sánh các khóa và giá trị của hai (hoặc nhiều) mảng và trả về một mảng có chứa các mục từ array1 có trong array2, array3, v.v.
Cú pháp
array_uintersect_uassoc(array1, array2, array3, ..., myfunc_key, myfunc_value)
Giá trị tham số
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. |
Chi tiết kỹ thuật
Giá trị trả lại: | Trả về một mảng chứa các mục từ array1 có trong tất cả các mảng khác |
---|---|
Phiên bản PHP: | 5+ |
❮ Tham chiếu mảng PHP