3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array=[ ['currency'=>'bitcoin','Totalcs'=>'1'], ['currency'=>'ethereum','Totalcs'=>'1'], ['currency'=>'ethereum','Totalcs'=>'1'] ]; foreach($array as $row){ // iterate all rows if(!isset($result[$row['currency']])){ // if first occurrence of currency... $result[$row['currency']]=$row; // save the full row with currency as the temporary key }else{ // if not the first occurrence of currency... $result[$row['currency']]['Totalcs']+=$row['Totalcs']; // add Totalcs value } } var_export(array_values($result));

preferences:
57.39 ms | 402 KiB | 5 Q