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

后端 未结 1 561
醉梦人生
醉梦人生 2021-01-01 12:30

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

相关标签:
1条回答
  • 2021-01-01 13:05
    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.

    0 讨论(0)
提交回复
热议问题