sort排序的各种例子~
<?php
/**
* QQ:5871029 Email:hel8@vip.qq.com
* @copyright Horleun (c)2010
* @author Horleun <Horleun@foxmail.com>
*/
$qq=array(“5″,”87″,”10″,”29″);
echo”asort排序<br/>”;
asort($qq);
print_r($qq);$qq=array(“5″,”87″,”10″,”29″);
echo”<br/>sort排序<br/>”;
sort($qq);
print_r($qq);$qq=array(“4″=>”5″,”1″=>”87″,”2″=>”10″,”3″=>”29″);
echo”<br/>ksort排序<br/>”;
ksort($qq);
print_r($qq);$qq=array(“5″,”87″,”10″,”29″);
echo”<br/>rsort排序<br/>”; //逆向
rsort($qq);
print_r($qq);$qq=array(“5″,”87″,”10″,”29″);
echo”<br/>arsort排序<br/>”;
arsort($qq);
print_r($qq);$qq=array(“4″=>”5″,”1″=>”87″,”2″=>”10″,”3″=>”29″);
echo”<br/>krsort排序<br/>”;
krsort($qq);
print_r($qq);?>
sort的各种排序~
上例结果如下:
asort排序
Array ( [0] => 5 [2] => 10 [3] => 29 [1] => 87 )
sort排序
Array ( [0] => 5 [1] => 10 [2] => 29 [3] => 87 )
ksort排序
Array ( [1] => 87 [2] => 10 [3] => 29 [4] => 5 )
rsort排序
Array ( [0] => 87 [1] => 29 [2] => 10 [3] => 5 )
arsort排序
Array ( [1] => 87 [3] => 29 [2] => 10 [0] => 5 )
krsort排序
Array ( [4] => 5 [3] => 29 [2] => 10 [1] => 87 )