3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ ["type"=>"WOW","order_no"=>1,"value"=>10], ["type"=>"WOW","order_no"=>8,"value"=>20], ["type"=>"DLR","order_no"=>10,"value"=>100], ["type"=>"DLR","order_no"=>2,"value"=>50], ["type"=>"WOW","order_no"=>3, "value"=>25] ]; $totalorders = 0; $totalvalue = 0; $final = array(); foreach($array as $k=>$v) { $custype = isset($v['type']) ? $v['type'] : null; $ordervalue = isset($v['value']) ? $v['value'] : null; if (!isset($final[$custype])) { $final[$custype] = array('orderdollars' => $ordervalue, 'ordercount' => 1); } else { $final[$custype]["orderdollars"] = $final[$custype]["orderdollars"] + $ordervalue; $final[$custype]["ordercount"]++; } $totalorders++; } print_r($final);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [WOW] => Array ( [orderdollars] => 55 [ordercount] => 3 ) [DLR] => Array ( [orderdollars] => 150 [ordercount] => 2 ) )

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:
33.67 ms | 401 KiB | 8 Q