"; <br>$k=var_dump(array_unique($r)); <br>return $k; <br>} <br>$a = array("red", "green", "pink", "red", "yellow","pink", "red"); <br>$r=my_array_same($a); <br>var_dump(array_unique($r)); <br>?> <br><br>输出结果: <br>array(2) { <br>[3]=> <br>string(3) "red" <br>[5]=> <br>string(4) "pink" <br>} <br><strong>3.还可以这么写: <br></strong><u>复制代码</u> 代码如下: <br><?php <BR>function my_array_intersect($arr1,$arr2){ <br>for($i=0;$i<count>$temp[]=$arr1[$i]; <br>} <br>for($i=0;$i<count>$temp[]=$arr2[$i]; <br>} <br>sort($temp); <br>$get=array(); <br>for($i=0;$i<count>if($temp[$i]==$temp[$i+1]) <br>$get[]=$temp[$i]; <br>} <br>return $get; <br>} <br>$array1 = array("green", "red", "blue"); <br>$array2 = array("green", "yellow", "red"); <br>echo "<pre class="brush:php;toolbar:false;">"; <br>print_r(my_array_intersect($array1, $array2)); <br>echo "<pre class="brush:php;toolbar:false;">
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号