如何合併數組與相同的鍵(使用日期作爲一個鍵)但不同的值?我曾經創建過一個代碼,但問題是每個密鑰只有一個存儲的值,但它們具有相同的密鑰(日期)。數組合並取決於數組密鑰
這裏是我的數組:
{
posting_date: "2017-08-08 00:00:00",
id: 1,
title: "activity 1",
category: "company_news"
},
{
posting_date: "2017-08-08 00:00:00",
id: 6,
title: "testing",
category: "building_process_update"
},
{
posting_date: "2017-08-08 00:00:00",
id: 7,
title: "ttest1",
category: "company_news"
},
這裏是我的代碼:
foreach ($result_post as $key => $value){
$year = date('Y',strtotime($value['posting_date']));
$month = date('M',strtotime($value['posting_date']));
$day = date('d',strtotime($value['posting_date']));
// $result[$year] = $value['posting_date'];
$data = [$value['title']];
$side_bar_date[$value['category']][$year][$month][$day] = ['id'=>$value['id'],'title'=>$value['title']];
}
但輸出
building_process_update: {
2017: {
Aug: {
08: {
id: 6,
title: "testing"
}
}
}
發佈預期結果 – RomanPerekhrest
我已經編輯了確切的輸出 – clien