我不完全确定您要做什么 - 我假设您希望每个不同 id 按 id 分组的总和,但我可能错了。
<?php
//result array of sums
$sums = array();
//example data
$source = array(
array('id'=>3, 'name'=>'some_name6', 'value'=>1.6),
array('id'=>1, 'name'=>'some_name', 'value'=>1.4),
array('id'=>1, 'name'=>'some_name2', 'value'=>7.2),
array('id'=>2, 'name'=>'some_name3', 'value'=>4.4),
array('id'=>1, 'name'=>'some_name4', 'value'=>1.2),
array('id'=>2, 'name'=>'some_name5', 'value'=>1.4),
);
foreach ($source as $ar) {
//create an entry for this id in the array of sums if does not exist.
if (!isset($sums[ $ar['id'] ])) {
$sums[ $ar['id'] ] = 0;
}
//add 'value' key to sum for that id
$sums[ $ar['id'] ] += $ar['value'];
}
//sort by id
ksort($sums);
print_r($sums);
/* output:
Array
(
[1] => 9.8
[2] => 5.8
[3] => 1.6
)
*/