How to Compare Two Arrays for Matching Values in PHP
In this lesson, we are going to see how to compare two arrays and find the matching values in PHP, we can do that using the array_intersect() function.
PHP array_intersect() Function
To accomplish this as we said we use the array_intersect() function.
<?php
$males = [
"name" => "John Doe",
"age" => 34,
"city" => "Paris"
];
$females = [
"name" => "Maria Maria",
"age" => 39,
"city" => "Paris"
];
$result = array_intersect($males, $females);
print_r($result);
//result
Array ( [city] => Paris )