【发布时间】:2018-12-06 19:16:08
【问题描述】:
如您所见,我有一个包含重复 orderid 的数组 因为一个订单可以有多个库存商品(库存商品名称)。如何合并数组,以便汇总总字段,orderid 不再重复,并且所有 stockitemnames 都放在同一个 orderId 下?
有人有办法解决这个问题吗?
Array ( [0] => Array
([orderId] => 1544100294
[total] => 215.28
[receivedate] => 0000-00-00
[stockitemname] => "The Gu" red shirt XML tag t-shirt (White) XXS
[customerid] => 10 )
[1] => Array
( [orderId] => 1544119651
[total] => 37.38
[receivedate] => 0000-00-00
[stockitemname] => USB rocket launcher (Gray)
[customerid] => 10 )
[2] => Array
( [orderId] => 1544100294
[total] => 1614.60
[receivedate] => 0000-00-00
[stockitemname] => Large sized bubblewrap roll 50m
[customerid] => 10 ) )
数组是根据这个查询的结果创建的:
SELECT oc.orderId, SUM(so.quantity*si.RecommendedRetailPrice) total, oc.receivedate, si.stockitemname, ru.customerid
FROM orderbycustomers oc
JOIN registered_users ru
ON oc.customerid = ru.customerid
JOIN stockitemorders so
ON oc.orderId = so.orderId
JOIN stockitems si
ON so.StockItemID = si.StockItemID
WHERE oc.customerid = $customerid
GROUP BY si.stockitemname
ORDER BY oc.receivedate
【问题讨论】:
-
是什么创建了这个数组?
标签: php arrays multidimensional-array array-merge