请教各位前辈,
两个数组arr1 arr2
想实现,如果arr2中存在arr1的某个值,就输出arr2已包含了arr1中的值
arr1 = Array( [0] => 7 [1] => 100);arr2 = Array( [0] => 2 [1] => 8 [2] => 9 [3] => 1001 [4] => 7 );if( ){echo "arr2已包含了arr1中的值";}
回复讨论(解决方案)
交集非空
count(array_intersect($A, $B))>0
$arr1 = Array(7, 100);
$arr2 = Array(2, 8, 9, 1001, 7);
print_r(array_uintersect($arr1, $arr2, "strcasecmp"));
使用函数array_intersect 可以实现你要的功能.
交集一下就知道了。$arr1 = array(1,2,3);$arr2 = array(1,3,4,5);check($arr1, $arr2);function check($arr1, $arr2){$result = array_intersect($arr1, $arr2);print_r($result);}
本文原创发布php中文网,转载请注明出处,感谢您的尊重!