Deleting duplicates of in a merged multidimensional array

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

dok300
New php-forum User
New php-forum User
Posts: 1
Joined: Tue Jul 30, 2013 4:50 pm

Deleting duplicates of in a merged multidimensional array

Postby dok300 » Wed Jul 31, 2013 7:04 am

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

Code: Select all

Array
(
    [0] => Array
        (
            [0] => Three Penn State Officials To Face Trial Over Sandusky Scandalfaroo
            [1] => (URL address blocked: See forum rules)
            [2] => 27
        )

    [1] => Array
        (
            [0] => Office meets Android: Microsoft takes smartphone app to Google’s home turf, avoids tabletsfaroo
            [1] => (URL address blocked: See forum rules)
            [2] => 7
        )

      [2] => Array
        (
            [0] => Three Penn State Officials To Face Trial Over Sandusky Scandalfaroo
            [1] => (URL address blocked: See forum rules)
            [2] => 14
        )

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 (URL address blocked: See forum rules) having a score in [2] of 41.

I have a basic outline of what to do;

Code: Select all

$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


Am new to php. Any advice is greatly appreciated.

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Deleting duplicates of in a merged multidimensional arra

Postby johnj » Fri Aug 02, 2013 2:20 am

please read about array_merge, array_merge_recursive and array_combine.


Return to “PHP coding => General”

Who is online

Users browsing this forum: Google [Bot] and 1 guest