将目标与干草堆相交,并确保交点与目标完全相等:
$haystack = array(...);$target = array('foo', 'bar');if(count(array_intersect($haystack, $target)) == count($target)){ // all of $target is in $haystack}
请注意,您只需要验证所得交集的大小是否与目标值数组的大小相同,即可说
$haystack是的超集
$target。
为了确认至少有一个值,
$target也是
$haystack,你可以这样做检查:
if(count(array_intersect($haystack, $target)) > 0){ // at least one of $target is in $haystack }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)