3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = 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" ) ); // create new associative array foreach($arr as $subarr){ $new[$subarr["username"]][] = $subarr; } // loop each username and create result array foreach($new as $user => $subarr){ $result[$user]["duration"] = array_sum(array_column($subarr, "chatduration")); // @ to supress notice if no open/closed is in array @$result[$user]["open"] = array_count_values(array_column($subarr, "status"))["open"]; @$result[$user]["closed"] = array_count_values(array_column($subarr, "status"))["closed"]; } $result["total"]["duration"] = array_sum(array_column($result, "duration")); $result["total"]["open"] = array_sum(array_column($result, "open")); $result["total"]["closed"] = array_sum(array_column($result, "closed")); var_dump($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 8
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 49
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 49
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 49
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 49
Branch analysis from position: 8
filename:       /in/UJn3G
function name:  (null)
number of ops:  84
compiled vars:  !0 = $arr, !1 = $subarr, !2 = $new, !3 = $user, !4 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   45     1      > FE_RESET_R                                       $6      !0, ->8
          2    > > FE_FETCH_R                                               $6, !1, ->8
   46     3    >   FETCH_DIM_R                                      ~7      !1, 'username'
          4        FETCH_DIM_W                                      $8      !2, ~7
          5        ASSIGN_DIM                                               $8
          6        OP_DATA                                                  !1
   45     7      > JMP                                                      ->2
          8    >   FE_FREE                                                  $6
   50     9      > FE_RESET_R                                       $10     !2, ->49
         10    > > FE_FETCH_R                                       ~11     $10, !1, ->49
         11    >   ASSIGN                                                   !3, ~11
   51    12        INIT_FCALL                                               'array_sum'
         13        INIT_FCALL                                               'array_column'
         14        SEND_VAR                                                 !1
         15        SEND_VAL                                                 'chatduration'
         16        DO_ICALL                                         $15     
         17        SEND_VAR                                                 $15
         18        DO_ICALL                                         $16     
         19        FETCH_DIM_W                                      $13     !4, !3
         20        ASSIGN_DIM                                               $13, 'duration'
         21        OP_DATA                                                  $16
   53    22        BEGIN_SILENCE                                    ~17     
         23        INIT_FCALL                                               'array_count_values'
         24        INIT_FCALL                                               'array_column'
         25        SEND_VAR                                                 !1
         26        SEND_VAL                                                 'status'
         27        DO_ICALL                                         $20     
         28        SEND_VAR                                                 $20
         29        DO_ICALL                                         $21     
         30        FETCH_DIM_R                                      ~22     $21, 'open'
         31        FETCH_DIM_W                                      $18     !4, !3
         32        ASSIGN_DIM                                               $18, 'open'
         33        OP_DATA                                                  ~22
         34        END_SILENCE                                              ~17
   54    35        BEGIN_SILENCE                                    ~23     
         36        INIT_FCALL                                               'array_count_values'
         37        INIT_FCALL                                               'array_column'
         38        SEND_VAR                                                 !1
         39        SEND_VAL                                                 'status'
         40        DO_ICALL                                         $26     
         41        SEND_VAR                                                 $26
         42        DO_ICALL                                         $27     
         43        FETCH_DIM_R                                      ~28     $27, 'closed'
         44        FETCH_DIM_W                                      $24     !4, !3
         45        ASSIGN_DIM                                               $24, 'closed'
         46        OP_DATA                                                  ~28
         47        END_SILENCE                                              ~23
   50    48      > JMP                                                      ->10
         49    >   FE_FREE                                                  $10
   56    50        INIT_FCALL                                               'array_sum'
         51        INIT_FCALL                                               'array_column'
         52        SEND_VAR                                                 !4
         53        SEND_VAL                                                 'duration'
         54        DO_ICALL                                         $31     
         55        SEND_VAR                                                 $31
         56        DO_ICALL                                         $32     
         57        FETCH_DIM_W                                      $29     !4, 'total'
         58        ASSIGN_DIM                                               $29, 'duration'
         59        OP_DATA                                                  $32
   57    60        INIT_FCALL                                               'array_sum'
         61        INIT_FCALL                                               'array_column'
         62        SEND_VAR                                                 !4
         63        SEND_VAL                                                 'open'
         64        DO_ICALL                                         $35     
         65        SEND_VAR                                                 $35
         66        DO_ICALL                                         $36     
         67        FETCH_DIM_W                                      $33     !4, 'total'
         68        ASSIGN_DIM                                               $33, 'open'
         69        OP_DATA                                                  $36
   58    70        INIT_FCALL                                               'array_sum'
         71        INIT_FCALL                                               'array_column'
         72        SEND_VAR                                                 !4
         73        SEND_VAL                                                 'closed'
         74        DO_ICALL                                         $39     
         75        SEND_VAR                                                 $39
         76        DO_ICALL                                         $40     
         77        FETCH_DIM_W                                      $37     !4, 'total'
         78        ASSIGN_DIM                                               $37, 'closed'
         79        OP_DATA                                                  $40
   59    80        INIT_FCALL                                               'var_dump'
         81        SEND_VAR                                                 !4
         82        DO_ICALL                                                 
         83      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.48 ms | 1018 KiB | 17 Q