Home > Backend Development > PHP Tutorial > 判断数组B是否存在数组A中的值

判断数组B是否存在数组A中的值

WBOY
Release: 2016-06-23 13:43:43
Original
1583 people have browsed it

请教各位前辈,
两个数组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中的值";}
Copy after login



回复讨论(解决方案)

交集非空
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);}
Copy after login

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template