我有这个数组:
$data = Array
(
[1] => Array
(
[id] => '52040344'
[outcome] => 0
[names] => Array
(
[name_eng] => 'this is a name 2'
)
)
[2] => Array
(
[id] => 54030157
[outcome] => 1108541
[names] => Array
(
[name_eng] => 'this is a name 1'
)
)
[3] => Array
(
[id] => '54030157
[outcome] => '109635'
[names] => Array
(
[name_eng] => 'this is a name 1'
)
)
)
我想返回一个数组,其中包含具有相同 id 的所有结果的总和,知道如果它们具有相同的 id,它们具有相同的名称。
所以我可以得到
array (
[0] => array( 'id' => '54030157', 'outcome' => 'sum of outcome', 'name' => 'this is name 1' ),
[1] => array( 'id' => '52040344', 'outcome' => 'sum of outcome', 'name' => 'this is name 2' )
)
我怎样才能做到这一点??
这是我到目前为止所尝试的:
public function process($data){
$outputArray = array();
foreach ($data as $key => $value) {
}
return $outputArray;
}
任何帮助,将不胜感激