🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
~~~ function dump($data) { echo "<pre>"; print_r($data); echo "</pre>"; die(); } $arr = [ [ 'price' => 10.5, 'sales' => 10, 'sales2' => 150, 'brand' => 'brand1' ], [ 'price' => 11.5, 'sales' => 20, 'sales2' => 200, 'brand' => 'brand1' ], [ 'price' => 30.5, 'sales' => 30, 'sales2' => 200, 'brand' => 'brand2' ], [ 'price' => 40.5, 'sales' => 40, 'sales2' => 400, 'brand' => 'brand3' ], [ 'price' => 50.5, 'sales' => 50, 'sales2' => 500, 'brand' => 'brand4' ], ]; $new_arr = []; foreach ($arr as $key => $value) { if(isset($new_arr[$value['brand']])) { $new_arr[$value['brand']] += $value['sales2']; } else { $new_arr[$value['brand']] = $value['sales2']; } } arsort($new_arr); dump($new_arr); ~~~