我有一个对象结构,它以雄辩的形式存储。
{"item_id": "2",
"item_color": "Black",
"item_size": "L",
"item_Quantity": "5",},
{"item_id": "2",
"item_color": "Black",
"item_size": "M",
"item_Quantity": "5",},
{"item_id": "2",
"item_color": "Black",
"item_size": "S",
"item_Quantity": "5",},
{"item_id": "2",
"item_color": "White",
"item_size": "S",
"item_Quantity": "5",},我试图实现的是将所有具有相同item_quantity的、item_id、和item_color合并起来,并以这样的表格形式显示。
ItemID ItemColor ItemSize Quantity Total
2 Black L-M-S 5-5-5 15
2 White S 5 5在我的研究中,这是最近的一种解决方案,但我很难以表格的形式显示它。
http://stackoverflow.com/questions/23902541/add-array-values-of-same-array-keys-in-session发布于 2015-08-03 06:23:27
$items = DB::table('item')
->select(DB::raw("item_id,item_color,GROUP_CONCAT(item_size SEPARATOR '-') as ItemSize,GROUP_CONCAT(item_Quantity SEPARATOR '-') as Quantity,sum(item_Quantity) as TOTAL"))
->groupBy('item_id','item_color')
->get();https://stackoverflow.com/questions/31780016
复制相似问题