数组

时间:2015-12-07 16:19:26

标签: php arrays

我有一个数组,其中我需要返回“价格”的平均值& “perUnitVolume”和“数量”年份的总和&月份比赛。例如,在该数组中,数组中的2个元素具有Year = 2014&月= 11,这些元素需要求和并求平均值。这是我的数组的简化输出(实际数组在数组中有> 1000个元素,有许多年和月的变体),只是不知道如何使用php获得我需要的结果。

Array
(
[0] => Array
    (
        [asin] => XXXXXX
        [price] => 19.99
        [qtyTotal] => 22
        [perUnitVolume] => 0.22
        [Month] => 2014
        [Year] => 11
        [Day] => 14
    )

[1] => Array
    (
        [asin] => YYYYYYY
        [price] => 24.99
        [qtyTotal] => 53
        [perUnitVolume] => 0.54
        [Month] => 2014
        [Year] => 11
        [Day] => 15
    )

[2] => Array
    (
        [asin] => XXXXXX
        [price] => 19.99
        [qtyTotal] => 13
        [perUnitVolume] => 0.99
        [Month] => 2015
        [Year] => 08
        [Day] => 16
    )
)

基本上最后我需要最终得到这个:

Array
(
[0] => Array
    (
        [asin] => XXXXXX
        [price] => 22.49 (average of 19.99 + 24.99 / 2)
        [qtyTotal] => 75 (sum of 22 + 53)
        [perUnitVolume] => 0.38 (average of 0.22 + 0.54 / 2)
        [Month] => 2014
        [Year] => 11
    )

[1] => Array
    (
        [asin] => YYYYYYY
        [price] => 19.99
        [qtyTotal] => 53
        [perUnitVolume] => 0.54
        [Month] => 2015
        [Year] => 08
    )
 )

0 个答案:

没有答案