dourunlao1642 2014-03-14 13:30
浏览 35
已采纳

使用键值[duplicate]在php中对多维数组进行排序

This question already has an answer here:

I want to sort the below array using php. The array should sort by value of services [0][1]...

Array
(
[Services] => Array
    (
        [0] => Travel & Hotels  ~72
        [1] => Automotive~119
        [3] => Professional Services~71
        [4] => Home Services~70
        [6] => IT Services & Computer Repair~83
        [8] => Health and Medical~69
    )

[Restaurants] => Array
    (
        [0] => American / Eclectic~2
        [1] => Cafe~11
        [2] => Desserts & Bakery~111
    )

[Shopping] => Array
    (
        [0] => Office Equipment~103
        [3] => Department Stores~91
        [15] => Cosmetics & Beauty Supply~90
        [16] => Musical Instruments & Teachers~102
        [17] => Food~87
    )

[Entertainment] => Array
    (
        [0] => Bars/Pubs~48
    )

[Travel] => Array
    (
        [0] => Hotels~129
    )
)
</div>
  • 写回答

1条回答 默认 最新

  • duanguoyin7008 2014-03-14 14:34
    关注

    It should be as simple as doing this (assuming that $attractionArray is the outer array given above):

    foreach($attractionsArray as $key => $innerArray)
    {
        sort($innerArray, SORT_STRING);
        $attractionArray[$key] = $innerArray;
    }
    

    See it in action here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号