//$fruits = array("d"=>"durian","a"=>"apple","b"=>"banana","c"=>"cherry","orange","lemon");
$fruits = array("c"=>"cherry","d"=>"durian","b" => "banana","a"=>"apple","orange","lemon");
echo "ksort 排序前:<br />";
print_r($fruits);
echo "<br>";
ksort($fruits);
echo "ksort 排序后:<br />";
print_r($fruits);
我以为结果会是按照key,数字挨着数字,字母挨着字母,可实际结果是
ksort 排序前:
Array
(
[c] => cherry
[d] => durian
[b] => banana
[a] => apple
[0] => peach
[1] => lemon
)
ksort 排序后:
Array
(
[0] => peach
[a] => apple
[b] => banana
[c] => cherry
[d] => durian
[1] => lemon
)
为什么 数字 0 不在数字家族的队伍当中呢?
并且 $fruits 按照 注释里的那样赋值,排序还会得到不同的结果