Would array_unique work here?

Hi,

I have a question, let’s say i have the following result in an array like so:

Array ( [0] =>
Array ( [HoldingID] => 1
[TypeID] => 1
[Title] => Text Detection and Localization
in Complex Scene Images using
Constrained AdaBoost
Algorithm
[Rating] => 87.5 )
[1] => Array ( [HoldingID] => 1
[TypeID] => 154
[Title] => Social Networking
[Rating] => 50 )
[2] => Array ( [HoldingID] => 2
[TypeID] => 2
[Title] => This is a test journal article
[Rating] => 60 )
[3] => Array ( [HoldingID] => 1
[TypeID] => 154
[Title] => Social Networking
[Rating] => 80 ) ) 1

Ok now you can see i have duplicate values, see array [1] and [3]. Now what i thought i could do is use array_unique to display the results without the duplicates…

Like so:


$rec = Recommendations::generateRecommendations($_GET['documents']);
          $result = array_unique($rec);
          die(print_r($result));

This shows me the following:

Array ( [0] => Array ( [HoldingID] => 1
[TypeID] => 1
[Title] => Text Detection and
Localization in Complex Scene
Images using Constrained
AdaBoost Algorithm
[Rating] => 87.5 ) ) 1

Now this is not what i want, what i need to do is from the first array example, check to see which one is the same and remove the one with the lowest [Rating]…

Is this possible?

Can anyone please point me in the right direction?

Thanks

If the source of the results is a database, you could ask it to only return unique entries. :wink:

Like most (if not all) php array functions they will not work on multi-dimensional arrays but a quick google (array_unique multidimensional) turned up this (and a few others):

http://www.phpdevblog.net/2009/01/using-array-unique-with-multidimensional-arrays.html

Hope this helps

Cheers,
Alex