检查看,如果一个数组的元素都在PHP中的另一个数组 [英] Checking to see if one array's elements are in another array in PHP

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

问题描述

我在PHP两个数组如下:

I have two arrays in PHP as follows:

人物:

Array
(
    [0] => 3
    [1] => 20
)

通缉犯:

Array
(
    [0] => 2
    [1] => 4
    [2] => 8
    [3] => 11
    [4] => 12
    [5] => 13
    [6] => 14
    [7] => 15
    [8] => 16
    [9] => 17
    [10] => 18
    [11] => 19
    [12] => 20
)

我如何检查任何个人的元素是在通缉犯的阵列?

在这个例子中,它应该返回真正,因为 20 中的通缉犯

In this example, it should return true because 20 is in Wanted Criminals.

先谢谢了。

推荐答案

您可以使用 array_intersect()

You can use array_intersect().

$result = !empty(array_intersect($people, $criminals));

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

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