PHP Version
4.3+
/* Find elements where both the key and value pairs are identical in another array */
$array1 = ['a' => 1, 'b' => 2, 'c' => 3]; // The base array used for comparison
$array2 = ['b' => 2, 'c' => 3, 'd' => 4];

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

/* Check the intersection between associative arrays */
$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 'There is data that remains consistent: ';

    foreach ($common as $key => $value) {
        echo $key . ': ' . $value . ' ';
    }
} else {
    echo 'No common data found.';
}
// Output: There is data that remains consistent: id: 1 name: John

/* Extract only the common elements based on specific key–value pairs */
$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' is stored as a string
$array2 = ['a' => 1, 'b' => 2, 'c' => 3];    // 3 is stored as an integer

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

print_r($intersect);
/* Output:
Array
(
    [a] => 1
    [b] => 2
    [c] => 3
)
*/
$array1 = array(0, 1, 2);           // Integers 0, 1, 2
$array2 = array('00', '01', '2');   // Strings '00', '01', '2'

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

print_r($result);
/* Output:
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 selected by the user
$filter_criteria = ['brand' => 'Samsung', 'price' => 800];

// Find products that match the selected criteria
$filtered_products = [];

foreach ($products as $product) {
    if (count(array_intersect_assoc($product, $filter_criteria)) === count($filter_criteria)) {
        $filtered_products[] = $product;
    }
}

// Output the result
print_r($filtered_products);
/*
Array
(
    [0] => Array
        (
            [id] => 2
            [name] => Smartphone
            [brand] => Samsung
            [price] => 800
        )
)
*/
// Information for two users
$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 to check whether matching keys and values exist
function has_matching_info($user_1, $user_2) {
    $matching_info = array_intersect_assoc($user_1, $user_2);

    // Return true if matching key–value pairs exist
    return !empty($matching_info);
}

// Output the result
if (has_matching_info($user_1, $user_2)) {
    echo 'There is matching information between the two users.';
} else {
    echo 'There is no matching information between the two users.';
}

// Output: 'There is no matching information between the two users.'
// Programming language preferences of user 1
$user1_languages = [
    'Python' => 4,
    'JavaScript' => 5,
    'Java' => 3,
];

// Programming language preferences of user 2
$user2_languages = [
    'JavaScript' => 5,
    'Java' => 4,
    'PHP' => 2,
];

// Function to find matching language preferences
function find_matching_languages($languages1, $languages2) {
    $matching_languages = array_intersect_assoc($languages1, $languages2);

    return $matching_languages;
}

// Output the result
$matching_languages = find_matching_languages($user1_languages, $user2_languages);

if (!empty($matching_languages)) {
    echo 'Both users prefer the same programming languages. ('
         . implode(', ', array_keys($matching_languages)) . ')';
} else {
    echo 'The two users do not share the same programming language preferences.';
}

// Output: Both users prefer the same programming languages. (JavaScript)