dsjbest2015 2015-11-26 04:06
浏览 87
已采纳

检查两个数组中的任何匹配[重复]

This question already has an answer here:

I have array like this

a1 = {1,3,5,7,9};
a2 = {2,4,6,8,9};

In both the arrays, there is a common value 9. I would like to know if there is a built in php function present which returns true or false if at least one value matches or not.

Thanks

</div>
  • 写回答

2条回答 默认 最新

  • dongmei1828 2015-11-26 04:10
    关注

    You could use array_intersect

    $a1 = [1,3,5,7,9];
    $a2 = [2,4,6,8,9];
    $a3 = [10];
    
    array_intersect($a1,$a2) ? true : false;
    // => true
    
    array_intersect($a1,$a3) ? true : false;
    // => false
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 C# datagridview 栏位进度
  • ¥15 vue3页面el-table页面数据过多
  • ¥100 vue3中融入gRPC-web
  • ¥15 kali环境运行volatility分析android内存文件,缺profile
  • ¥15 写uniapp时遇到的问题
  • ¥15 vs 2008 安装遇到问题
  • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改