I have this array:
array(
array('id' => 1, 'price' => 20.00, 'stock' => 2, 'year' => 11 ),
array('id' => 1, 'price' => 20.00, 'stock' => 3, 'year' => 12 ),
array('id' => 1, 'price' => 20.00, 'stock' => 2, 'year' => 13 ),
array('id' => 2, 'price' => 36.00, 'stock' => 11, 'year' => 13 ),
);
I need to sum the "stock" column when the id is the same (is the same article) and the years are 12 AND 13.
The result should be:
array(
array('id' => 1, 'price' => 20.00, 'stock' => 2, 'year' => 11 ),
array('id' => 1, 'price' => 20.00, 'stock' => 5, 'year' => 13 ),
array('id' => 2, 'price' => 36.00, 'stock' => 11, 'year' => 13 ),
);
Notice the 'year' => 12 has been removed and the stock of that row has been added to the 13 row.
I can't do this without creating a big mess of spaguetti code with a bunch of bucles. Maybe there is a php function to this in a cleaner way?
Sorry for my english.