//1.sort() 索引数组按照值的字母升序排 $fruits = array( "lemon" , "orange" , "banana" , "apple" ); sort ( $fruits ); foreach ( $fruits as $key => $val ) { echo "fruits[" . $key . "] = " . $val . " " ; } echo '<hr/>';//apple、banana、orange、lemon //2.asort()(注:关联、索引)数组按照值的字母排序 $fruits = array( "d" => "lemon" , "a" => "orange" , "b" => "banana" , "c" => "apple" ); asort ( $fruits ); foreach ( $fruits as $key => $val ) { echo " $key = $val " ; } //apple、banana、lemon、orange //注:当数组是索引数组时使用asort的排序结果和sort一样但是asort索引会保持排序前的顺序 //3.ksort()按照索引来字母升序排 $fruits = array( "d" => "lemon" , "a" => "orange" , "b" => "banana" , "c" => "apple" ); ksort ( $fruits ); foreach ( $fruits as $key => $val ) { echo " $key = $val " ; } //array('a'=>'orange','b'=>'banana','c'=>'apple','d'=>'lemon');