tags:

views:

115

answers:

2

Two associative arrays A and B: how do I check if any value of from array A exists in array B without a foreach or any other loop?

Is this possible?

There is array_key_exists and in_array but they search for values in an array, not values from an array in another array.

Hope this makes some kind of sense :)

+5  A: 

You can use array_intersect(A,B) to get a list of values present in both arrays.

Zed
A: 
function is_array_a_in_array_b($a, $b) {
    $aa = array_unique($a);
    return count(array_intersect($aa, $b)) == count($aa);
}
Anatoliy