<?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
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
array_intersect()返回的数组带第一个数组的key值,所以$result2的key是0=>green,2=>red,请print_R($result2),一看即知
echo $v."<br />";