<!-- 数组排序
sort对数组进行升序排列
rsort对数组进行降序排列
asort根据关联数组的值,对数组进行升序排列
ksort根据关联数组的键,对数组进行升序排列
arsort根据关联数组的值对数组进行降序排序
krsort根据数组的键,对数组进行降序排序-->
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php
$cars = array("volvo","BMW","Toyato");
sort($cars);//这个是对数组进行升序排序,当然对于数组的值是字符串的时候,是按照字符串的第一个字母进行排序
for($x=0;$x<count($cars);$x++)
{
echo $cars[$x];
echo "<br>";
}
rsort($cars);
for($y=0;$y<count($cars);$y++)
{
echo $cars[$y];
//要知道的是无论在数组或者是在一般的变量的
//前面都是应该加上$这个符号的
echo "<br>";
}
$carss=array("peter"=>"35","joe"=>"40","Tom"=>"56");
asort($carss);
foreach ($carss as $x => $x_value) {
echo "Name=".$x.",Age=".$x_value;
}
ksort($carss);//对于中我们应该知道的是每个语句的最后面double应该加上一个分号
foreach ($carss as $y => $y_value) {
echo "Name=".$y.",Age=".$y_value;
}
?>
</body>
</html>
sort对数组进行升序排列
rsort对数组进行降序排列
asort根据关联数组的值,对数组进行升序排列
ksort根据关联数组的键,对数组进行升序排列
arsort根据关联数组的值对数组进行降序排序
krsort根据数组的键,对数组进行降序排序-->
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php
$cars = array("volvo","BMW","Toyato");
sort($cars);//这个是对数组进行升序排序,当然对于数组的值是字符串的时候,是按照字符串的第一个字母进行排序
for($x=0;$x<count($cars);$x++)
{
echo $cars[$x];
echo "<br>";
}
rsort($cars);
for($y=0;$y<count($cars);$y++)
{
echo $cars[$y];
//要知道的是无论在数组或者是在一般的变量的
//前面都是应该加上$这个符号的
echo "<br>";
}
$carss=array("peter"=>"35","joe"=>"40","Tom"=>"56");
asort($carss);
foreach ($carss as $x => $x_value) {
echo "Name=".$x.",Age=".$x_value;
}
ksort($carss);//对于中我们应该知道的是每个语句的最后面double应该加上一个分号
foreach ($carss as $y => $y_value) {
echo "Name=".$y.",Age=".$y_value;
}
?>
</body>
</html>