我有一个包含以下值的数组
Array
(
[0] => Array
(
[order_date] => 2016-01-01
[sku] => RK101
[qty] => 2
)
[1] => Array
(
[order_date] => 2016-01-01
[sku] => RK101
[qty] => 5
)
[2] => Array
(
[order_date] => 2016-01-01
[sku] => RK102
[qty] => 4
)
[3] => Array
(
[order_date] => 2016-01-02
[sku] => RK101
[qty] => 2
)
[4] => Array
(
[order_date] => 2016-01-02
[sku] => RK101
[qty] => 2
)
)
我希望您能够对数组进行求和,首先按日期,然后按SKU,我希望得到以下结果:
Array
(
[2016-01-01] => Array
(
[RK101] => Array
(
[qty] => 7
)
[RK102] => Array
(
[qty] => 4
)
)
[2016-01-01] => Array
(
[RK101] => Array
(
[qty] => 4
)
)
)
我已经探索了Stack Overflow并发现了许多计算基于一个关键字的总和的帖子,但在这种情况下,我想首先按日期计算数组值的总和,然后再按sku计算。 请帮忙解决这个问题。