Checking to see if one array's elements are in another array in PHP
So you have 2 arrays:
$a = array("a", "b", "c", "d");
$b = array("x", "y", "z", "b", "o");
And you want to check if one of the array a's item are in the b array, here is how:
if( !empty(array_intersect($a, $b))) {
echo "Gotcha!";
};
$a = array("a", "b", "c", "d");
$b = array("x", "y", "z", "b", "o");
And you want to check if one of the array a's item are in the b array, here is how:
if( !empty(array_intersect($a, $b))) {
echo "Gotcha!";
};
Comments
Post a Comment