Tamik Soziev
Tamik Soziev

Reputation: 14798

php - how to check if at least one element of first array exists in second array

I have two arrays : array("blue", "yellow") and array("blue", "green", "red", "purple"). Is there a function that will check if those two arrays have at least one element value in common ("blue") - just return true or false.

Upvotes: 21

Views: 9307

Answers (1)

Travesty3
Travesty3

Reputation: 14479

$array1 = array("blue", "yellow");
$array2 = array("blue", "green", "red");

return count(array_intersect($array1, $array2)) > 0;

Upvotes: 49

Related Questions