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);
Output for git.master, git.master_jit, rfc.property-hooks
array(3) { ["bhavin"]=> array(3) { ["duration"]=> float(1197.1299999999999) ["open"]=> int(1) ["closed"]=> int(1) } ["lokesh"]=> array(3) { ["duration"]=> float(132.482) ["open"]=> NULL ["closed"]=> int(2) } ["total"]=> array(3) { ["duration"]=> float(1329.6119999999999) ["open"]=> int(1) ["closed"]=> int(3) } }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
172.74 ms | 406 KiB | 5 Q