Home > php教程 > PHP源码 > PHP array_intersect函数

PHP array_intersect函数

PHP中文网
Release: 2016-05-25 17:15:06
Original
1152 people have browsed it

PHP array_intersect函数

/**
 * 
 * 自定义的array_intersect
 * 如果求的是一维数组的交集这个函数比系统的array_intersect快5倍
 *
 * @param array $arr1
 * @param array $arr2
 * @author  LIUBOTAO  2010-12-13上午11:40:20
 *
 */
function my_array_intersect($arr1,$arr2)
{
    for($i=0;$i<sizeof($arr1);$i++)
    {
        $temp[]=$arr1[$i];
    }
    
    for($i=0;$i<sizeof($arr1);$i++)
    {
        $temp[]=$arr2[$i];
    }
    
    sort($temp);
    $get=array();
    
    for($i=0;$i<sizeof($temp);$i++)
    {
        if($temp[$i]==$temp[$i+1])
         $get[]=$temp[$i];
    }
    
    return $get;
}

$array1 = array("green", "red", "blue");
$array2 = array("green", "yellow", "red");
echo "<pre class="brush:php;toolbar:false">";
print_r(my_array_intersect($array1, $array2));
echo "<pre/>";
Copy after login

 以上就是PHP array_intersect函数的内容,更多相关内容请关注PHP中文网(m.sbmmt.com)!


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
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template