Home  >  Article  >  Backend Development  >  PHP判断两个数组是否存在交集的方法

PHP判断两个数组是否存在交集的方法

WBOY
WBOYOriginal
2016-06-20 13:03:413001browse

PHP判断两个数组是否存在交集,函数代码如下:

<p>/***************判断两个数组是否存在交集******************/</p>function get_array_intersection($array_A,$array_B){<br />	if(!isset($array_A) || !isset($array_B) || !is_array($array_A) || !is_array($array_B) || empty($array_A) || empty($array_B)){<br />		return false;<br />	}<br />	foreach($array_A as $temp){<br />		if(in_array($temp,$array_B)){<br />			return true;<br />		}<br />	}<br />	unset($array_A,$array_B,$temp);<br />	return false;<br />}


Statement:
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