<?php
/*
PHP 数组排序
数组中的元素能够以字母或数字顺序进行升序或降序排序。
PHP - 数组的排序函数:
* sort() - 以升序对数组排序
* rsort() - 以降序对数组排序
* asort() - 根据值,以升序对关联数组进行排序
* ksort() - 根据键,以升序对关联数组进行排序
* arsort() - 根据值,以降序对关联数组进行排序
* krsort() - 根据键,以降序对关联数组进行排序
*/
# 对数组进行升序排序 - sort()
$cars = array("Volvo", "BMW", "SAAB");
sort($cars);
$numbers = array(3, 5, 1, 22, 11);
sort($numbers);
# 对数组进行降序排序 - rsort()
$cars = array("Volvo", "BMW", "SAAB");
rsort($cars);
$numbers = array(3, 5, 1, 22, 11);
rsort($numbers);
# 根据值对数组进行升序排序 - asort()
$age = array("Bill"=>"35", "Steve"=>"37", "Peter"=>"43");
asort($age);
# 根据键对数组进行升序排序 - ksort()
$age = array("Bill"=>"35", "Steve"=>"37", "Peter"=>"43");
asort($age);
# 根据值对数组进行降序排序 - arsort()
$age = array("Bill"=>"35", "Steve"=>"37", "Peter"=>"43");
arsort($age);
# 根据键对数组进行降序排序 - krsort()
$age = array("Bill"=>"35", "Steve"=>"37", "Peter"=>"43");
krsort($age)
?>