我有一个表Commande,其中包含prestataire_iddateheure,...,所以我想按日期对表进行重新分组。我试过了

$commande = $this->Commande->find('all', array('conditions' => array('Commande.prestataire_id' => $this->request->data['prestataire_id']),'order' =>    array('Commande.date' => 'DESC')));


json响应就是这样

{
    "status": "Success",
    "status_code": 200,
    "message": "Commande trouvé",
    "data": {
        "get_Mission": {
            "data": [
                {
                    "Commande": {
                        "id": "475",
                        "date": "2018-04-20",
                        "heure": "10:00:00",
                        "date_created": "2018-04-19",
                        "heure_created": "17:11:39",
                        "date_accepted": "2018-04-19",
                        "heure_accepted": "17:12:35",
                        "delai": "00:00:56",
                        "date_fin": "0000-00-00",
                        "heure_fin": "00:00:00",

                    },


                },
                {
                    "Commande": {
                        "id": "476",
                        "date": "2018-04-20",
                        "heure": "10:07:00",
                        "date_created": "2018-04-19",
                        "heure_created": "17:13:12",
                        "date_accepted": "0000-00-00",
                        "heure_accepted": "00:00:00",
                        "delai": "0",
                        "date_fin": "0000-00-00",
                        "heure_fin": "00:00:00",

                    },

                },

                {
                    "Commande": {
                        "id": "477",
                        "date": "2018-04-19",
                        "heure": "17:13:00",
                        "date_created": "2018-04-19",
                        "heure_created": "17:13:48",
                        "date_accepted": "2018-04-19",
                        "heure_accepted": "17:14:23",
                        "delai": "00:00:35",
                        "date_fin": "0000-00-00",
                        "heure_fin": "00:00:00",

                    },

                }
            ]
        }
    }
}


但我希望按日期重新组合它们,例如数据["2018-04-20"]-> {commande,commande}["2018-04-19"]->{"commande}有什么建议吗?

最佳答案

您可以尝试将月份设置为阵列键。

    foreach($examples as $example){
        $month = date('Y-m-d', strtotime($example['Model']['date']));
        $exampleArray[$month][] = $example;
    }


并在设置后重新使用$ exampleArray。

09-25 15:43