$val){
echo "fruits[".$key."]=".$val."
" ;
}
/*运行结果为:
fruits[0]=Orange
fruits[1]=apple
fruits[2]=banana
fruits[3]=lemon
*/
$fruits = array("lemon","Orange","banana","apple");
sort($fruits,SORT_NATURAL | SORT_FLAG_CASE ); //不区分大小写自然排序
foreach($fruits as $key=>$val){
echo "fruits[".$key."]=".$val."
" ;
}
echo"
";
echo"
";
echo"
";
echo"
";
echo"
";
$fruits = array("lemon","Orange","banana","apple");
rsort($fruits,SORT_NATURAL | SORT_FLAG_CASE ); //不区分大小写自然排序
foreach($fruits as $key=>$val){
echo "fruits[".$key."]=".$val."
" ;
}
//使用rsort()函数进行数组排序。
$fruits = array("lemon","Orange","banana","apple");
sort($fruits );
foreach($fruits as $key=>$val){
echo "fruits[".$key."]=".$val."
" ;
}
echo"
";
echo"
";
echo"
";
echo"
";
echo"
";
$fruits = array("lemon","Orange","banana","apple");
rsort($fruits,SORT_NATURAL | SORT_FLAG_CASE ); //不区分大小写自然排序
foreach($fruits as $key=>$val){
echo "fruits[".$key."]=".$val."
" ;
}
//使用ksort()函数和krsort()函数进行数组索引排序。
echo"
";
echo"
";
echo"
";
echo"
";
echo"
";
$citylist = array('shoudu'=>'Beijing','sichuan'=>'Chengdu',
'hubei'=>'Wuhan','zhejiang'=>'Hangzhou');
ksort($citylist); //按索引排序--升序,不打乱索引和值的对应性
foreach($citylist as $key=>$value){
echo $key.'----'.$value.'
';
}
echo"
";
echo"
";
echo"
";
echo"
";
echo"
";
$citylist = array('shoudu'=>'Beijing','sichuan'=>'Chengdu',
'hubei'=>'Wuhan','zhejiang'=>'Hangzhou');
krsort($citylist); //按索引排序--降序,不打乱索引和值的对应性
foreach($citylist as $key=>$value){
echo $key.'----'.$value.'
';
}
echo"
";
echo"
";
echo"
";
echo"
";
echo"
";