gpt4 book ai didi

php - 返回 array_intersect 作为 bool 值

转载 作者:行者123 更新时间:2023-12-01 10:19:38 27 4
gpt4 key购买 nike

我有两个数组,我需要检查它们是否有共同的值,并且返回值必须是 bool 值。
我可以用array_intersect()像这样还是有更好的方法?

$result = (bool) array_intersect($array1, $array2);

谢谢你。

最佳答案

只需检查array_intersect($array1, $array2)的内容

$result = count(array_intersect($array1, $array2)) > 0;

关于php - 返回 array_intersect 作为 bool 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54765852/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com