A simple solution to a PHP array problem is needed?

roh_sjcs

New Member
I actually am quite embarrassed to ask such a question but it is one of those days that you spend 10 thousand hours on the simplest of functions and the more you try to solve them the more complicated a solution you get.... I don't want to waste more time so here is the problem.I have one array:\[code\] $items=array( 0=> array('name'=>'red','value'=>2), 1=> array('name'=>'black','value'=>1), 2=> array('name'=>'red','value'=>3) );\[/code\]And I need a function that detects the identical names and merges them adding up their values. This means after the function finishes the array should look like this:\[code\] $items=array( 0=>array('name'=>'red','value'=>5), 1=>array('name'=>'black','value'=>1) );\[/code\]('red' has two entries that have values 2 and 3, after the operation, red should have 1 entry with the value 5)Thanks.
 
Back
Top