gpt4 book ai didi

php - 如何检查数组的任何值是否存在于另一个数组 php 中?

转载 作者:IT王子 更新时间:2023-10-28 23:51:35 24 4
gpt4 key购买 nike

我有两个数组

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

如何在不使用循环的情况下检查数组$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

很可能在幕后使用了一个循环,这可能毫无值(value)。

关于php - 如何检查数组的任何值是否存在于另一个数组 php 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11789897/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com