adding values in array where id's are the same php -


i have array. in array there 2 [id] values same. able add [score] of these elements , merge elements [id] same. possible?

[0] =>           [id] => 9428          [auth] => manual          [firstname] => tariq          [lastname] => essop          [score] => 75.000000000          [timecreated] => 1366093740          [courseid] => 215          [itemname] => 2164 date of assessment , dispute resolution          [itemid] => 750 )   [1] =>          [id] => 9428          [auth] => manual          [firstname] => tariq          [lastname] => essop          [score] => 75.000000000          [timecreated] => 1366100428          [courseid] => 215          [itemname] => 2168 cross-border loans , intellectual property          [itemid] => 751 )  [2] =>          [id] => 6258          [auth] => manual          [firstname] => tariq          [lastname] => essop          [score] => 75.000000000          [timecreated] => 1366100428          [courseid] => 215          [itemname] => 2168 cross-border loans , intellectual property          [itemid] => 752 ) 

$data = array();  foreach ($array $item) {     if (!isset($data[$item['id']])) {         $data[$item['id']] = $item;     } else {         // whatever need $data[$item['id']], e.g.:         $data[$item['id']]['score'] += $item['score'];     } } 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -