Reputation: 12618
I am trying to check if any values out or array $a1 are present in array $a2 in PHP...
$a1 = array(
"a"=>"red",
"b"=>"green",
"c"=>"blue",
"d"=>"yellow"
);
$a2 = array(
"b"=>"green",
"c"=>"blue",
);
I have tried to compare using in_array
like this...
if (in_array($a1, $a2)) {
echo "Match found";
}
But this is not working, I think this is because in_array does not support checking an array against an array. What is the correct method?
Upvotes: 0
Views: 35
Reputation: 6388
You can use array_intersect_assoc
$res =array_intersect_assoc($a1, $a2);
Upvotes: 3