PHP array_intersect_uassoc() 함수
예시
두 배열의 키와 값 을 비교하고 일치 항목을 반환합니다(사용자 정의 키 비교 함수 사용).
<?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("d"=>"red","b"=>"green","e"=>"blue");
$result=array_intersect_uassoc($a1,$a2,"myfunction");
print_r($result);
?>
정의 및 사용
array_intersect_uassoc() 함수는 두 개(또는 그 이상) 배열 의 키와 값 을 비교하고 일치 항목을 반환합니다.
참고: 이 함수는 사용자 정의 함수를 사용하여 키를 비교합니다!
이 함수는 두 개 이상의 배열의 키와 값을 비교하고 array2 , array3 등에 있는 array1 의 항목을 포함하는 배열을 반환합니다.
통사론
array_intersect_uassoc(array1, array2, array3, ..., myfunction)
매개변수 값
Parameter | Description |
---|---|
array1 | Required. The first array is the array that the others will be compared with |
array2 | Required. An array to be compared with the first array |
array3,... | Optional. An array to be compared with the first array |
myfunction | Required. 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
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"=>"green","d"=>"blue");
$a3=array("e"=>"yellow","a"=>"red","d"=>"blue");
$result=array_intersect_uassoc($a1,$a2,$a3,"myfunction");
print_r($result);
?>
❮ PHP 배열 참조