摘要:
下文讲述php中数组排序的方法分享,如下所示;
实现思路:
php中提供一些原生态的数组排序函数,如下:
sort():对数组进行升序排列
rsort():对数组进行降序排列
asort():使用关联数组的值,对数组进行升序排列
ksort():使用关联数组的键,对数组进行升序排列
arsort():使用关联数组的值,对数组进行降序排列
krsort():使用关联数组的键,对数组进行降序排列
下文将通过示例的方式讲述数据的排序
echo "maomao365.com 数组长度获取的示例分享:\n";
$a=array("m","a","t");
sort($a);
$b=array(8,16,56,2,99);
sort($b);
$c=array("m","a","t");
rsort($c);
$d=array(8,16,56,2,99);
rsort($d);
$e=array("m"=>"1","a"=>"2","t"=>"3");
asort($e);
$f=array("m"=>"1","a"=>"2","t"=>"3");
arsort($f);
$g=array("m"=>"1","a"=>"2","t"=>"3");
ksort($g);
$h=array("m"=>"1","a"=>"2","t"=>"3");
krsort($h);
var_dump($a);
var_dump($h);
?>