简体   繁体   English

如何在另一个数组php中检查数组的任何值?

[英]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? 如何在不使用循环的情况下检查数组$ b中是否存在数组$ a的任何值?

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 http://php.net/manual/en/function.array-intersect.php

Probably worth nothing that, in all likelihood, under the hood, a loop is used. 可能毫无价值,很可能在引擎盖下,使用循环。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM