duandang2123 2014-02-18 08:55
浏览 19

PHP排序表[重复]

This question already has an answer here:

Simple functions like PHP_SORT doesn't work, also tips from comments couldn't help me enough. I'm trying to sort my table by int values but I can't manage it. This is sample of my table.

array(3) {
 ["normal"]=>
 array(20) {
[58]=>
int(7343)
[33]=>
int(7032)
[34]=>
int(7322)
[65]=>
int(7017)
[60]=>
int(6996)
[62]=>
int(7022)
[35]=>
int(6508)
[56]=>
int(7323)
[61]=>
int(413)
[57]=>
int(7327)
[67]=>
int(7001)
[72]=>
int(6469)
[64]=>
int(5297)
[59]=>
int(5135)
[71]=>
int(5322)
[70]=>
int(5452)
[69]=>
int(6556)
[68]=>
int(6436)
[66]=>
int(6840)
[48]=>
int(6862)
 }
 ["high"]=>
array(19) {
[58]=>
int(2717)
[60]=>
int(2562)
[33]=>
int(2718)
[34]=>
int(2722)
[61]=>
int(1964)
[64]=>
int(2337)
[65]=>
int(368)
[67]=>
int(2308)
[72]=>
int(1880)
[59]=>
int(2202)
[57]=>
int(2587)
[56]=>
int(1474)
[62]=>
int(2416)
[48]=>
int(2455)
[35]=>
int(2356)
[69]=>
int(1910)
[71]=>
int(2229)
[68]=>
int(2293)
[63]=>
int(2582)
 }
  ["low"]=>
 array(12) {
[58]=>
int(1905)
[48]=>
int(1771)
[60]=>
int(1842)
[56]=>
int(1179)
[57]=>
int(1714)
[64]=>
int(1243)
[34]=>
int(1903)
[63]=>
int(57)
[59]=>
int(1837)
[35]=>
int(1725)
[62]=>
int(1594)
[33]=>
int(1858)
 }
}

Please give me some tips. I will be very pleased.

SOLUTION:

$newArray = array();
foreach($morning_code as $k=>$subArray){
   arsort($subArray);
   $newArray[$k] = $subArray;
}
var_dump($newArray);
</div>
  • 写回答

2条回答 默认 最新

  • douzhenggui8171 2014-02-18 08:55
    关注

    You can use arsort to sort your array.

    <?php arsort(array); ?>

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度