首页 新闻 会员 周边 捐助

请问 PHP 中 数组ksort()数字键名和字母键名混排,排序规则是什么?

0
[待解决问题]

//$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 按照 注释里的那样赋值,排序还会得到不同的结果
PHP
咕咚诺娃的主页 咕咚诺娃 | 菜鸟二级 | 园豆:202
提问于:2015-05-15 18:14
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册