发布于 2022-08-01 12:39:09 浏览 381 次
案例1
<?php
$cars = array("Volvo","BMW","Toyota");
sort($cars);
?>
输出
Array ( [0] => BMW [1] => Toyota [2] => Volvo )
案例2
<?php
$numbers = array(4,6,2,22,11);
sort($numbers);
?>
输出
Array ( [0] => 2 [1] => 4 [2] => 6 [3] => 11 [4] => 22 )
sort()
2、
案例1
<?php
$cars=array("Volvo","BMW","Toyota");
rsort($cars);
?>
输出
Array ( [0] => Volvo [1] => Toyota [2] => BMW )
案例2
<?php
$numbers = array(4,6,2,22,11);
rsort($numbers);
?>
输出
Array ( [0] => 22 [1] => 11 [2] => 6 [3] => 4 [4] => 2 )
rsort()
3、
案例
<?php
$age = array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
asort($age);
?>
输出
Array ( [Peter] => 35 [Ben] => 37 [Joe] => 43 )
asort()
4、
案例
<?php
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
ksort($age);
?>
输出
Array ( [Ben] => 37 [Joe] => 43 [Peter] => 35 )
ksort()
5、
案例
<?php
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
arsort($age);
?>
输出
Array ( [Joe] => 43 [Ben] => 37 [Peter] => 35 )
arsort()
6、
案例
<?php
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
krsort($age);
?>
输出
Array ( [Peter] => 35 [Joe] => 43 [Ben] => 37 )
krsort()