In this function I'm filtering my DB output. I don't know how to get unique values only. My array:
[2] => Array (
[name] => John
[id] => D
)
[4] => Array (
[name] => Grace
[id] => K
)
[6] => Array (
[name] => John
[id] => U
)
Now I want a new array which has to contain only the first "John" and "Grace", because they are 'unique'. What I've tried?
array_unique($filtredrow, "name");
But after that function I'm only receiving names and I have to get also ids of unique people.
Thank you for help!
EDIT This is what I want to get:
[2] => Array (
[name] => John
[id] => D
)
[4] => Array (
[name] => Grace
[id] => K
)
My loading data in which I've tried not to save elements which are already in array.
$rows=$mydb->get_resoults("SELECT DISTINCT name, id FROM DB", ARRAY_A);
foreach($rows as $key=>$row)
{
if($row[name]!=null && $row[id]!=null)
{
if($filtredrow[$key][name]!=$row[name])
{
$filtredrow[$key][name]=$row[name];
$filtredrow[$key][id]=$row[id];
}
}
}
But it's saving all values :/ also duplicates