我有一个表Commande
,其中包含prestataire_id
,date
,heure
,...所以我想按日期重新组合表格。我试过这个
$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}
有任何建议吗?
答案 0 :(得分:0)
您可以尝试将月份设置为数组键。
foreach($examples as $example){
$month = date('Y-m-d', strtotime($example['Model']['date']));
$exampleArray[$month][] = $example;
}
设置后重新使用$ exampleArray。