I have an array $rows that looks like the following:
Array
(
[0] => Array
(
[type] => post
[object_id] => 1
[language_id] => 1
[score] => 2
)
[1] => Array
(
[type] => category
[object_id] => 46
[language_id] => 1
[score] => 1
)
[2] => Array
(
[type] => product
[object_id] => 50
[language_id] => 1
[score] => 1
)
[3] => Array
(
[type] => category
[object_id] => 59
[language_id] => 1
[score] => 1
)
[4] => Array
(
[type] => post
[object_id] => 1
[language_id] => 1
[score] => 1
)
)
I need to loop through this array and when a duplicate type and object_id matches, increment the score and delete the duplicate array. I can't seem to find a way to do this.
Using the example above, key 0 has type post and object_id 1, and so does key 4. Key 0 score should be incremented to itself + key 4 score and key 4 should be deleted.
My end result should look like this:
Array
(
[0] => Array
(
[type] => post
[object_id] => 1
[language_id] => 1
[score] => 3
)
[1] => Array
(
[type] => category
[object_id] => 46
[language_id] => 1
[score] => 1
)
[2] => Array
(
[type] => product
[object_id] => 50
[language_id] => 1
[score] => 1
)
[3] => Array
(
[type] => category
[object_id] => 59
[language_id] => 1
[score] => 1
)
)