PHP 버전
4.3+
/* 다른 배열과 키(Key)와 값(Value) 쌍이 모두 동일한 공통 요소 찾기 */
$array1 = ['a' => 1, 'b' => 2, 'c' => 3]; // 비교 기준이 되는 배열
$array2 = ['b' => 2, 'c' => 3, 'd' => 4];

$result = array_intersect_assoc($array1, $array2);
print_r($result); // Array ( [b] => 2 [c] => 3 )

/* 연관 배열 간의 공통 요소(intersection) 확인 */
$current_user_info = ['id' => 1, 'name' => 'John', 'age' => 30];
$updated_user_info = ['id' => 1, 'name' => 'John', 'age' => 31];

$common = array_intersect_assoc($updated_user_info, $current_user_info);

if (!empty($common)) {
    echo '공통으로 유지되는 데이터가 있습니다: ';

    foreach ($common as $key => $value) {
        echo "$key: $value ";
    }
} else {
    echo '공통 데이터가 없습니다.';
}
// 출력: '공통으로 유지되는 데이터가 있습니다: id: 1 name: John'

/* 특정 키와 값 쌍을 기준으로 연관 배열에서 공통 요소만 추출하기 */
$original_array = ['id' => 1, 'name' => 'John', 'age' => 30];

$criteria = ['name' => 'John'];

$result = array_intersect_assoc($original_array, $criteria);
print_r($result); // Array ( [name] => John )
array_intersect_assoc(array $array_1, $array_2, $array_3, ...): array
$array1 = ["a" => 1, "b" => 2, "c" => 3];
$array2 = ["b" => 3, "c" => 4, "d" => 5];

$common_elements = array_intersect_assoc($array1, $array2);

print_r($common_elements); // Array ( )
$array = ["a" => 1, "b" => 2, "c" => 3];

$result = array_intersect_assoc($array);

print_r($result);
/* Output:
Array
(
    [a] => 1
    [b] => 2
    [c] => 3
)
*/
$array1 = ['a' => 1, 'b' => 2, 'c' => '3'];  // '3'은 문자열로 저장
$array2 = ['a' => 1, 'b' => 2, 'c' => 3];    // 3은 정수로 저장

$intersect = array_intersect_assoc($array1, $array2);

print_r($intersect);
/* 출력:
Array
	(
	    [a] => 1
	    [b] => 2
	    [c] => 3
	)
*/
$array1 = array(0, 1, 2);           // 정수 0, 1, 2
$array2 = array('00', '01', '2');   // 문자열 '00', '01', '2'

$result = array_intersect_assoc($array1, $array2);

print_r($result);
/* 출력:
Array
(
    [2] => 2
)
*/
$products = [
    ['id' => 1, 'name' => 'Laptop',     'brand' => 'Dell',     'price' => 1200],
    ['id' => 2, 'name' => 'Smartphone', 'brand' => 'Samsung', 'price' => 800],
    ['id' => 3, 'name' => 'Tablet',     'brand' => 'Apple',   'price' => 600],
    ['id' => 4, 'name' => 'Smartwatch', 'brand' => 'Fitbit',  'price' => 150],
];

// 사용자가 선택한 필터 조건
$filter_criteria = ['brand' => 'Samsung', 'price' => 800];

// 사용자가 선택한 조건과 일치하는 상품 찾기
$filtered_products = [];
foreach ($products as $product) {
    if (count(array_intersect_assoc($product, $filter_criteria)) === count($filter_criteria)) {
        $filtered_products[] = $product;
    }
}

// 결과 출력
print_r($filtered_products);
/*
Array
(
    [0] => Array
        (
            [id] => 2
            [name] => Smartphone
            [brand] => Samsung
            [price] => 800
        )
)
*/
// 두 사용자의 정보
$user_1 = [
    'id' => 1,
    'username' => 'john_doe',
    'email' => 'john@example.com',
    'age' => 30,
];

$user_2 = [
    'id' => 2,
    'username' => 'jane_smith',
    'email' => 'jane@example.com',
    'age' => 28,
];

// 두 사용자의 정보에서 동일한 키와 값이 있는지 확인하는 함수
function has_matching_info($user_1, $user_2) {
    $matching_info = array_intersect_assoc($user_1, $user_2);

    // 동일한 키와 값이 있는 경우 반환
    return !empty($matching_info);
}

// 결과 출력
if (has_matching_info($user_1, $user_2)) {
    echo '두 사용자의 정보에서 일치하는 내용이 있습니다.';
} else {
    echo '두 사용자의 정보에서 일치하는 내용이 없습니다.';
}

// 출력: '두 사용자의 정보에서 일치하는 내용이 없습니다.'
// 사용자 1의 프로그래밍 언어 선호도
$user1_languages = [
    'Python' => 4,
    'JavaScript' => 5,
    'Java' => 3,
];

// 사용자 2의 프로그래밍 언어 선호도
$user2_languages = [
    'JavaScript' => 5,
    'Java' => 4,
    'PHP' => 2,
];

// 두 사용자의 프로그래밍 언어 선호도 중에서 동일한 언어를 찾는 함수
function find_matching_languages($languages1, $languages2) {
    $matching_languages = array_intersect_assoc($languages1, $languages2);

    return $matching_languages;
}

// 결과 출력
$matching_languages = find_matching_languages($user1_languages, $user2_languages);

if (!empty($matching_languages)) {
    echo '두 사용자가 동일한 프로그래밍 언어를 선호합니다. ('
         . implode(', ', array_keys($matching_languages)) . ')';
} else {
    echo '두 사용자가 동일한 프로그래밍 언어를 선호하지 않습니다.';
}

// 출력: 두 사용자가 동일한 프로그래밍 언어를 선호합니다. (JavaScript)