doubei5310 2018-01-15 01:10
浏览 24
已采纳

PHP多数组排序方法

If I have this array:

//$myarray
Array (
    [0] => Array (
        [b163cb25371a1b7c550d8f69fe211cc8] => Array (
            [unique_key]        => 14f74cf38563b889386beeec511033e2
            [thwepof_options]   => Array (
                [order_date] => Array (
                    [name] => order_date
                    [value] => 1
                    [label] => Szállítási nap
                    [options] =>
                )
            )
        )
    )
 )

How can I write a sorting method which sort the values by order_date [value]

I've tried first to get the array column like this but didn't got any return value:

<?php
$days = array_column($myarray[0]['thwepof_options'], 'value', 'order_date');
?>
  • 写回答

1条回答 默认 最新

  • doutinghou6980 2018-01-15 02:14
    关注

    You are skipping the 2nd level key. Here's a working version of your code:

    <?php
    $myarray = Array (
        0 => Array (
            'b163cb25371a1b7c550d8f69fe211cc8' => Array (
                'unique_key'        => '14f74cf38563b889386beeec511033e2',
                'thwepof_options'   => Array (
                    'order_date' => Array (
                        'name' => 'order_date',
                        'value' => 1,
                        'label' => 'Szállítási nap',
                        'options' => null
                    )
                )
            )
        )
     );
    
    $days = array_column($myarray[0]['b163cb25371a1b7c550d8f69fe211cc8']['thwepof_options'], 'value', 'order_date');
    
    print_r($days);
    

    Also, this thing looks to me like it would make more sense as an object.

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

报告相同问题?

悬赏问题

  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错