0

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 :)

2 Answers 2

5

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

Sign up to request clarification or add additional context in comments.

Comments

0
function is_array_a_in_array_b($a, $b) {
    $aa = array_unique($a);
    return count(array_intersect($aa, $b)) == count($aa);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.