Actually, I’m very ashamed to ask such a question, but on one of these days you spend 10 thousand hours on the simplest functions, and the more you try to solve their more complex solution that you will get ... I do not want to spend more time, therefore here is the problem.
I have one array:
$items=array(
0=> array('name'=>'red','value'=>2),
1=> array('name'=>'black','value'=>1),
2=> array('name'=>'red','value'=>3)
);
And I need a function that detects identical names and combines them by adding their values. This means that after the function finishes, the array should look like this:
$items=array(
0=>array('name'=>'red','value'=>5),
1=>array('name'=>'black','value'=>1)
);
('red' has two entries that have values 2 and 3, after the operation red should have 1 entry with a value of 5)
Thank.
source
share