Got a multidimensional array like this one:
[['key'=>'foo', 'Rating'=>5] ,
['key'=>'bar', 'Rating'=>1] ,
['key'=>'Tee', 'Rating'=>3] ,
['key'=>'foo', 'Rating'=>10] ,
['key'=>'foo', 'Rating'=>1]]
I want to remove duplicates based on a specific key and a Rating system while maintaining the original array structure except index keys.
So the final result should look like this:
[['key'=>'bar', 'Rating'=>1] ,
['key'=>'Tee', 'Rating'=>3] ,
['key'=>'foo', 'Rating'=>10]]
I'm looking for an efficient solution to this problem.
Ideally an array_unique() function that accepts a key value as a parameter to find repetitions on a given array and the Rating key.
array_key_unique($array, $uniqe_key, $Rating);
I was wondering if there is any way to do this with MySQL query?
['key'=>'foo', 'Rating'=>5] ,is a duplicate and need to remove. look at your desired output and tellkey, MAX(Rates.Rating) FROM Rates GROUP BY Rates.key