【发布时间】:2017-01-07 07:52:56
【问题描述】:
我有以下代码:
while($row12 = mysql_fetch_array($result12)) {
$position = $row12['position'];
$tot[$k] = $row12['total'];
$k++;
}
$arr = arsort($tot);
for($x = 0; $x < $k; $x++) {
echo $tot[$x]."<br>";
}
我已经能够根据数据库记录创建总计数组,但需要按降序对值进行排序。
例如排序前:
- 107
- 563
- 109
- 246
- 897
排序后:
- 897
- 563
- 246
- 109
- 107
【问题讨论】:
-
您可以对 sql 查询中的值进行排序。我认为这比在 php 中要快得多。 php.net/manual/en/array.sorting.php 在这里你可以阅读关于使用 php 函数进行排序...所以你不必实现自己的排序函数
-
我知道这一点,但它无法解决问题,因为我尝试过
-
去掉烂英文,清晰显示输入输出再码累
-
代码格式只在内容的开头起作用
标签: php mysql arrays sorting indexed