- sort()对数组进行升序排列
- rsort()对数组进行降序排列
- asrot()根据关联数组的值,对数组进行升序排列
- arsort()根据关联数组的值,对数组进行降序排列
- ksort()根据关联数组的键,对数组进行升序排列
- krsort()根据关联数组的键,对数组进行降序排列
对数组$car进行排序
$car = [
'a'=>20,
'c'=>15,
'b'=>25
];
- sort - 对数组进行升序排列
sort($car);
//打印$car
Array
(
[0] => 15
[1] => 20
[2] => 25
)
- rsort - 对数组进行升序排列
rsort($car);
//打印$car
Array
(
[0] => 25
[1] => 20
[2] => 15
)
- asrot()根据关联数组的值,对数组进行升序排列
asort($car);
//打印$car
Array
(
[c] => 15
[a] => 20
[b] => 25
)
- arsrot()根据关联数组的值,对数组进行降序排列
arsort($car);
//打印$car
Array
(
[b] => 25
[a] => 20
[c] => 15
)
- ksort()根据关联数组的键,对数组进行升序排列
ksort($car);
//打印$car
Array
(
[a] => 20
[b] => 25
[c] => 15
)
- krsort()根据关联数组的键,对数组进行降序排列
krsort($car);
//打印$car
Array
(
[c] => 15
[b] => 25
[a] => 20
)