EbinPaulose EbinPaulose - 10 months ago 46
PHP Question

How check any value of array exist in another array php?

I have two array

$a = array('a','b');
$b = array('a','1','2','3','4');


How to checks any value of array $a exists in array $b without using loop?

Answer Source
if (count(array_intersect($array1, $array2)) === 0) {
  // No values from array1 are in array 2
} else {
  // There is at least one value from array1 present in array2
}

http://php.net/manual/en/function.array-intersect.php

Probably worth nothing that, in all likelihood, under the hood, a loop is used.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download