【问题标题】:Grouping of array content数组内容的分组
【发布时间】:2013-02-26 11:25:34
【问题描述】:

这是我需要按订单 ID 显示结果的数组,我们在其中显示一次 ID 以及与其关联的所有项目。每个ID中有多个项目,所有按ID的订单都会显示在屏幕上(当然有分页)..只是排序很麻烦..有什么帮助吗?

    $this->data['transactions'][] = array(

    'amount' => $result['total'],

    'firstname' => $result['firstname'],

    'lastname' => $result['lastname'],

    'id' => $result['order_id'],

    'telephone' => $result['telephone'],

    'quantity' => $result['quantity'],

    'name' => $result['name'],

    'price' => $this->currency->format($result['price'],$this->config->get('config_currency')),

    'total' => $result['total']
    );

我希望输出到 b 显示为

日期 OrderID CustomerName Tele Amount

产品

产品

产品

【问题讨论】:

    标签: php arrays


    【解决方案1】:

    如果排序有问题,请使用:

    $your_array = $this->data['transactions'];
    $sort = array();
    foreach($your_array as $k=>$v) {
        $sort['id'][$k] = $v['id'];
    }
    
    array_multisort($sort['id'], SORT_DESC, $your_array);
    
    
    echo "<pre>";
    print_r($your_array);
    

    【讨论】:

    • 您好 Prasanth,感谢您的回复。我遇到的问题是显示最终输出,其中列出了具有相同 ID 的所有订单。有什么建议吗?
    猜你喜欢
    • 1970-01-01
    • 2011-11-25
    • 1970-01-01
    • 1970-01-01
    • 2019-10-14
    • 1970-01-01
    • 2016-10-22
    • 2016-06-06
    • 1970-01-01
    相关资源
    最近更新 更多