Modifying a merged array

I am trying to iterates through an array, replace duplicates and increment the score when duplicates are found.

[php]Array
(
[0] => Array
(
[0] => Three Penn State Officials To Face Trial Over Sandusky Scandalfaroo
[1] => http://www.inquisitr.com/880628/three-penn-state-officials-to-face-trial-over-sandusky-scandal/
[2] => 27
)

[1] => Array
    (
        [0] => Office meets Android: Microsoft takes smartphone app to Google’s home turf, avoids tabletsfaroo
        [1] => http://www.geekwire.com/2013/office-meets-android-microsoft-takes-smartphone-app-googles-home-turf-avoids-tablets/
        [2] => 7
    )

  [2] => Array
    (
        [0] => Three Penn State Officials To Face Trial Over Sandusky Scandalfaroo
        [1] => http://www.inquisitr.com/880628/three-penn-state-officials-to-face-trial-over-sandusky-scandal/
        [2] => 14
    )[/php]

I have a merged array above and I want to combine duplicate urls and increase the score when duplicates are found. So the above would consist of two results, with http://www.inquisitr.com/880628/three-penn-state-officials-to-face-trial-over-sandusky-scandal/ having a score in [2] of 41.

I have a basic outline of what to do;

[php]
$array_two = array_merge($faroo_array,$blekko_array);// already done

$deduplicate=array();//create new array

foreach($array_two as $value) //loop over the merged array
{
if(isset ($deduplicate[$n])) //getting lost- this is supposed to be array[1] on second iteration array[2] on second etc, with $n being a counter so it loops through.
deduplicate[$n][2]= $value[$n][2] //merge two urls
deduplicate[$n][2]= $value[$n][2] // add score

else
$deduplicate[$n][1] = $value[$n][$1];//otherwise add url to new array

}

print_r($deduplicate); //output new aggregated array
[/php]

Any advice is greatly appreciated.

Maybe a more elegant way but here’s off the top of my head:

[php]$list = array();

foreach($array_two as $k => $v) {
if(($prev = array_search($v[1], $list)) !== false) { //if url is already in $list
$array_two[$prev][2] += $v[2]; //add current url score to previous url score
unset($array_two[$k]); //remove current entry
} else { //if url is not in $list
$list[] = $v[1]; //add url to $list
}
}[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service