检查多个值是否存在 php 数组 [英] check multiple values exists php array

查看:50
本文介绍了检查多个值是否存在 php 数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 PHP 中有一个数组

I have an array in PHP

$permission = array( "admin", "moderator", "guest"  );

我还有另一个数组

$userRoles = array( "admin", "moderator" );

我检查了 in_array 但它不适用于多个值.

I checked with in_array but it doesn't work with multiple values.

如何在不循环的情况下检查 $userRoles 中是否存在 $permission 中的至少一个值?

How can i check atleast one value in $userRoles exists on $permission without looping ?

提前致谢.

推荐答案

使用 array_intersect

count(array_intersect($permission, $userRoles));

这篇关于检查多个值是否存在 php 数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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