<?php /** * Created by PhpStorm. * User: Administrator * Date: 2022/4/20/020 * Time: 15:52 $fruits = array("lemon","Orange","banana","apple"); sort($fruits ); foreach($fruits as $key=>$val){ echo "fruits[".$key."]=".$val."<br />" ; } /*运行结果为: 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."<br />" ; } echo"<br>"; echo"<br>"; echo"<br>"; echo"<br>"; echo"<br>"; $fruits = array("lemon","Orange","banana","apple"); rsort($fruits,SORT_NATURAL | SORT_FLAG_CASE ); //不区分大小写自然排序 foreach($fruits as $key=>$val){ echo "fruits[".$key."]=".$val."<br />" ; } //使用rsort()函数进行数组排序。 $fruits = array("lemon","Orange","banana","apple"); sort($fruits ); foreach($fruits as $key=>$val){ echo "fruits[".$key."]=".$val."<br />" ; } echo"<br>"; echo"<br>"; echo"<br>"; echo"<br>"; echo"<br>"; $fruits = array("lemon","Orange","banana","apple"); rsort($fruits,SORT_NATURAL | SORT_FLAG_CASE ); //不区分大小写自然排序 foreach($fruits as $key=>$val){ echo "fruits[".$key."]=".$val."<br />" ; } //使用ksort()函数和krsort()函数进行数组索引排序。 echo"<br>"; echo"<br>"; echo"<br>"; echo"<br>"; echo"<br>"; $citylist = array('shoudu'=>'Beijing','sichuan'=>'Chengdu', 'hubei'=>'Wuhan','zhejiang'=>'Hangzhou'); ksort($citylist); //按索引排序--升序,不打乱索引和值的对应性 foreach($citylist as $key=>$value){ echo $key.'----'.$value.'<br />'; } echo"<br>"; echo"<br>"; echo"<br>"; echo"<br>"; echo"<br>"; $citylist = array('shoudu'=>'Beijing','sichuan'=>'Chengdu', 'hubei'=>'Wuhan','zhejiang'=>'Hangzhou'); krsort($citylist); //按索引排序--降序,不打乱索引和值的对应性 foreach($citylist as $key=>$value){ echo $key.'----'.$value.'<br />'; } echo"<br>"; echo"<br>"; echo"<br>"; echo"<br>"; echo"<br>";