<?php
function printStr($str){
                for($x=0;$x<count($str);$x++){
                        echo $str[$x];
                        echo "<br>";
                }
                echo "end";
                echo "<br>";
        }  
 $array1 = array ("green","red","yello");
 $array2 = array ("green", "blue","red");
  
  $result1 = array_intersect ($array1, $array2);  $array3 = array ("green","yello","red");
  $array4 = array ("green", "blue","red");  $result2 = array_intersect ($array3, $array4);printStr($result1);
printStr($result2);
?>
结果为什么是:
green
red
end
green
end 

解决方案 »

  1.   

    用 print_r($array)打印,,你的自写遍历输出数组不对
      

  2.   

    你自定义的函数有问题,为什么不直接foreach?
    array_intersect()返回的数组带第一个数组的key值,所以$result2的key是0=>green,2=>red,请print_R($result2),一看即知
      

  3.   

    array_intersect 返回的数组中的下标是不连续的,不能用 for 循环遍历
      

  4.   

    foreach($result2 as $v)
    echo $v."<br />";