douyin4875 2015-06-05 22:14
浏览 32
已采纳

以奇怪的格式对数组进行排序

I have an array as below:

Array
(
    [time] => Array
        (
            [0] => 6:00 PM
            [1] => 4:00 PM
        )

[id] => Array
    (
        [0] => #1 Hits of the 60's
        [1] => 3 Men and a Lady
    )

[url] => Array
    (
        [0] => hits-of-the-60
        [1] => 3-men-and-a-lady
    )

[ev_evc_id] => Array
    (
        [0] => 2
        [1] => 2
    )

[address] => Array
    (
        [0] => Caravelle Theatre
        [1] => God and Country Theatre
    )

[phone] => Array
    (
        [0] => 1-800-4Branson (800-427-2676)
        [1] => 1-800-4Branson (800-427-2676)
    )

)

I want to sort the array based on time ascending.

Desired output is as below:

Array
(
    [time] => Array
        (
            [0] => 4:00 PM
            [1] => 6:00 PM
        )
[id] => Array
    (
        [0] => 3 Men and a Lady
        [1] => #1 Hits of the 60's
    )

[url] => Array
    (
        [0] => 3-men-and-a-lady
        [1] => hits-of-the-60
    )

[ev_evc_id] => Array
    (
        [0] => 2
        [1] => 2
    )

[address] => Array
    (
        [0] => God and Country Theatre
        [1] => Caravelle Theatre
    )

[phone] => Array
    (
        [0] => 1-800-4Branson (800-427-2676)
        [1] => 1-800-4Branson (800-427-2676)
    )

)

I have tried asort, usort. But could not make it work. Any help / suggestion is appreciated.

  • 写回答

2条回答 默认 最新

  • douzhengyi5022 2015-06-05 22:49
    关注

    You can do it with array_multisort, it will sort all arrays based on the first array given:

    array_multisort(
        $myArray["time"],
        $myArray["id"],
        $myArray["url"],
        $myArray["ev_evc_id"],
        $myArray["address"],
        $myArray["phone"]
    );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

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