开发者

array_unique/super_unique problem

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)));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜