如何检查,如果一个数组中的元素完全在PHP另一个数组存在 [英] How to check if one array elements entirely exists in another array in php

查看:495
本文介绍了如何检查,如果一个数组中的元素完全在PHP另一个数组存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个阵列,例如:

array1={1,2,3,4,5,6,7,8,9};
array2={4,6,9}

有没有什么函数,这样我可以确定数组2 完全数组1

我知道我可以使用 in_array()函数在一个循环,但在情况下,我将有数百元素,所以我搜索功能大型阵列。

I know i can use the in_array() function in a loop but in cases where I will have large arrays with hundreds of elements so I am searching for a function.

推荐答案

尝试:

$fullyExists = (count($array2) == count(array_intersect($array2, $array1));

的<一个href=\"http://www.php.net/manual/en/function.array-intersect.php\"><$c$c>array_intersect.php函数将返回第二阵列是在所有其他参数present(仅在这种情况下,第一阵列)的唯一元素。所以,如果该交点的长度等于所述第二阵列的lenght,第二阵列完全被第一个载

The array_intersect.php function will return only elements of the second array that are present in all the other arguments (only the first array in this case). So, if the length of the intersection is equal to the lenght of the second array, the second array is fully contained by the first one.

这篇关于如何检查,如果一个数组中的元素完全在PHP另一个数组存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆