duanchouyi6730 2016-12-18 04:57
浏览 76
已采纳

如果两个数组中的任何元素匹配,则返回true? [重复]

This question already has an answer here:

I've two arrays, one is my define array and another I process from the database. Is there any proper way to compare between those arrays?

From database:

$user_type = [0 => "public" 1 => "10x413" 2 => "12x432"]

Defined array:

$specificUser = ['10x410','10x411','10x412','10x413','10x414'] 

If any element matches, then return true, just like php in_array() function.

</div>
  • 写回答

2条回答 默认 最新

  • doulu8415 2016-12-18 05:09
    关注

    Just loop and check as you would using in_array() to get the value that matches:

    foreach($specificUser as $value) {
        if(in_array($value, $user_type)) {
            echo $value;
            //break; to stop checking, a match was found, or not to continue and see more
        }
    }
    

    Or to just test for any match:

    if(array_intersect($specificUser, $user_type)) {
        // it's true :-)
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP