0
我需要合併按名稱分組的數組中的對象,以便對於每個名稱,我將「forecast」和「actuals」的名稱作爲同一對象的一部分返回。如何合併laravel中的對象? 「預測」和「實際」來自同一個表的兩個單獨的數據庫查詢。如何通過名稱鍵合併這些數組對象?
Collection {#464
#items: array:3 [
"Peters Sow" => Collection {#459
#items: array:2 [
0 => array:4 [
"name" => "Peters Sow"
"from" => "2017-06-01"
"to" => "2017-06-30"
"actuals" => 1
]
1 => array:4 [
"name" => "Peters Sow"
"from" => "2017-06-01"
"to" => "2017-06-30"
"forecast" => 1
]
]
}
因此,它可以像這樣以預測和實際作爲一個名稱彼得斯母豬下。
Collection {#464
#items: array:3 [
"Peters Sow" => Collection {#459
#items: array:2 [
0 => array:4 [
"name" => "Peters Sow"
"from" => "2017-06-01"
"to" => "2017-06-30"
"actuals" => 1
"forecast" => 1
]
嘗試了這一點https://stackoverflow.com/questions/28226507/merge-2-arrays-of-objects-in-php/28226533 –