PHP 버전
4.0.1+
/* 인덱스 배열끼리의 비교 */

$index_array1 = [1, 2, 3, 4, 5]; // 비교 대상이 되는 배열
$index_array2 = [2, 3, 4, 6, 7];

$index_unique_value = array_intersect($index_array1, $index_array2);

print_r($index_unique_value);
출력
/* 연관 배열끼리의 비교 */

$assoc_array1 = [  // 비교 대상이 되는 배열
	'a' => 'apple',
	'b' => 'banana',
	'c' => 'carrot',
	'd' => 'date'
];

$assoc_array2 = [
	'x' => 'carrot',
	'b' => 'grape',
	'y' => 'apple'
];

$assoc_unique_value = array_intersect($assoc_array1, $assoc_array2);

print_r($assoc_unique_value);
출력
/* 인덱스 배열과 연관 배열의 비교 */

$arr_idx = ['a', 'b', 'c'];  // 비교 대상이 되는 배열

$arr_assoc = [
    'x' => 'b',
    'y' => 'c',
    'z' => 'd'
];

$assoc_unique_value = array_intersect($assoc_array1, $assoc_array2);

print_r($assoc_unique_value);
출력
array_intersect(array $array_1, array_2, $array_3, ...): array
$array1 = [1, 2, 3, 4, 5];
$array2 = [6, 7];

$result = array_intersect($array1, $array2);
print_r($result); // Array ( )
$array = [1, 2, 2, 3, 4, 4, 5];

$uniqueValues = array_intersect($array);
print_r($uniqueValues);
// PHP 8.0.0 이후 버전에서는 하나의 배열만 전달 가능
/* 출력:
	Array
	(
	    [0] => 1
	    [1] => 2
	    [2] => 2
	    [3] => 3
	    [4] => 4
	    [5] => 4
	    [6] => 5
	)
*/
$array = [1, 2, 2, 3, 4, 4, 5];

$counts = array_count_values($array);
$duplicates = array_filter($counts, function($count) {
    return $count > 1;
});

print_r(array_keys($duplicates)); // Array ( [0] => 2 [1] => 4 )
$array1 = ['a' => 1, 'b' => 2, 'c' => 3];
$array2 = ['x' => 1, 'y' => 2, 'z' => 3];

$result = array_intersect($array1, $array2);
print_r($result); // 출력: Array ( [a] => 1 [b] => 2 [c] => 3 )
$array1 = [1, 2, '3'];  // '3'은 문자열
$array2 = [1, 2, 3];    // 3은 정수

$differences = array_intersect($array1, $array2);

print_r($differences); // Array ( [0] => 1 [1] => 2 [2] => 3 )
$userIdsFromDatabase = [1, 2, 3, 4, 5];
$selectedUserIds = [2, 4, 6, 8, 10];

$commonUserIds = array_intersect($userIdsFromDatabase, $selectedUserIds);
print_r($commonUserIds); // Array ( [1] => 2 [3] => 4 )
$submittedTags = ['php', 'javascript', 'html'];
$allowedTags = ['html', 'css', 'javascript', 'python'];

$validTags = array_intersect($submittedTags, $allowedTags);
print_r($validTags); // Array ( [2] => javascript [1] => html )
$adminPermissions = ['read', 'write', 'delete', 'update'];
$userPermissions = ['read', 'write'];

$allowedPermissions = array_intersect($adminPermissions, $userPermissions);
print_r($allowedPermissions); // Array ( [0] => read [1] => write )
$availableProducts = ['product1', 'product2', 'product3', 'product4'];
$selectedProducts = ['product2', 'product4', 'product5'];

$inStockProducts = array_intersect($availableProducts, $selectedProducts);
print_r($inStockProducts); // Array ( [1] => product2 [3] => product4 )