<?php
error_reporting(0); //5.6需要 7以上不需要
$res = [
[
'name' => 'a',
'age' => 12,
'number' => 11,
'score' => 50,
],
[
'name' => 'a',
'age' => 12,
'number' => 11,
'score' => 30,
],
[
'name' => 'b',
'age' => 12,
'number' => 12,
'score' => 50,
]
];
$new_arr = [];
foreach ($res as $index => $item) {
$tmp = $item['name'] . '-' . $item['age'];
$new_arr[$tmp]['name'] = $item['name'];
$new_arr[$tmp]['age'] = $item['age'];
$new_arr[$tmp]['score'] += $item['score'] . ',';
//$res[$index]['score'] = rtrim($new_arr[$tmp]['score'],',');
}
var_dump(array_values($new_arr));
//var_dump($res);