I am trying to remove duplicates based on 'duplicate_check' for the following array. It seems neither array_unique nor super_unique function works. I also tried to compare two identical arrays with a loop inside a loop function, but it runs out of time because there are tens of thousands lines in the array. Any help?

[1] => Array
    (
        [a] => abc
        [b] => 202
        [c] => 001
        [d] => 
        [e] => Graphic Commun
        [duplicate_check] => abc202001
    )

[2] => Array
    (
        [a] => abc
        [b] => 211
        [c] => 001
        [d] => Bard
        [e] => CAD Fundamentals
        [duplicate_check] => abc211001
    )
 [3] => Array
    (
        [a] => abc
        [b] => 211
        [c] => 001
        [d] => 
        [e] => 
        [duplicate_check] => abc211001
    )
有帮助吗?

解决方案

Well, I don't know about your tried approach (you should add that to your question). But it seems you should just use a loop to filter entries:

$found = array();
foreach ($array as $i=>$row) {

    $check = "$row[a],$row[b],$row[c]";
    //$check = $row["duplicate_check"];

    if (@$found[$check]++) {
        unset($array[$i]);
    }
}

A lazy solution (but probably not to your task) could also be:

=array_map("unserialize", array_unique(array_map("serialize", $array)));
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top