如果数组键在php中相同,则汇总数组值

时间:2015-08-20 12:39:26

标签: php arrays

我一直在搞乱这个很长一段时间,但找不到办法。任何帮助将不胜感激!

所以我有以下数组:

Array
(
[0] => Array
    (
        [user_agent] => iPhone
        [occurrences] => 113
    )

[1] => Array
    (
        [user_agent] => iPhone
        [occurrences] => 69
    )

[2] => Array
    (
        [user_agent] => iPhone
        [occurrences] => 39
    )

[3] => Array
    (
        [user_agent] => iPhone
        [occurrences] => 38
    )

[4] => Array
    (
        [user_agent] => iPhone
        [occurrences] => 24
    )

[5] => Array
    (
        [user_agent] => iPad
        [occurrences] => 23
    )

[6] => Array
    (
        [user_agent] => iPhone
        [occurrences] => 19
    )

[7] => Array
    (
        [user_agent] => iPhone
        [occurrences] => 12
    )

[8] => Array
    (
        [user_agent] => Windows
        [occurrences] => 4
    )

[9] => Array
    (
        [user_agent] => Macintosh
        [occurrences] => 3
    )

所需的结果如下:

Array 
(
   [user_agent]=>iPhone
   [occurrences] => //numbers added from old array where user agent is iPhone..

   .. so on with all different user_agents
)

提前致谢!

0 个答案:

没有答案