dqx76962 2018-02-23 07:23
浏览 38

多维数组中的用户计数

I have array look like below. And I want to do sum of chatduration for userwise.

And also want to count below 3 detail from status

  1. close_chat
  2. open_chat
  3. total chat.

    Array
        (
           [0] => Array
                (
                    [id] => pZgauDZtvQ9grRD9c
                    [rid] => obHEGwnrfHKCd32jF
                    [starttime] => 14-02-2018
                    [chatduration] => 124.502
                    [username] => bhavin
                    [status] => open
                )
    
            [1] => Array
                (
                    [id] => ej5WfYe3dn8mtHzQF
                    [rid] => o6pKCt4e6RaYiZhQ8
                    [starttime] => 14-02-2018
                    [chatduration] => 1072.628
                    [username] => bhavin
                    [status] => closed
                )                                                        
    
            [2] => Array
                (
                    [id] => qCzZjf7vb4rSBRndk
                    [rid] => ZFvuuFiL9RFiemX3K
                    [starttime] => 14-02-2018
                    [chatduration] => 11.254
                    [username] => lokesh
                    [status] => closed
                )
    
            [3] => Array
                (
                    [id] => TCdSycFFSeY8WaKzG
                    [rid] => f7ADPWFsCD6RZFspk
                    [starttime] => 14-02-2018
                    [chatduration] => 121.228
                    [username] => lokesh
                    [status] => closed
                )
    
        )
    

    And from this array I want to take sum chatduration userwise. Sum of bhavin user and lokesh user should be store in array.

How can this possible?

  • 写回答

4条回答 默认 最新

  • dongtuo2373 2018-02-23 07:33
    关注

    You can sum the chat duration like this:

    $duration = array_sum(array_column($userArray,'chatduration'));
    

    You can get your counts like this:

    $counts = array_count_values(array_column($userArray,'status'));
    

    This last one will return an array using the values of array as keys and their frequency in array as values.

    评论

报告相同问题?

悬赏问题

  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏