array_unique/super_unique问题

发布于 2024-10-24 11:55:22 字数 716 浏览 2 评论 0原文

我正在尝试根据以下数组的“duplicate_check”删除重复项。看来 array_unique 和 super_unique 函数都不起作用。我还尝试将两个相同的数组与循环函数内的循环进行比较,但它耗尽了时间,因为数组中有数万行。有什么帮助吗?

[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
    )

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
    )

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜无邪 2024-10-31 11:55:22

好吧,我不知道你尝试过的方法(你应该将其添加到你的问题中)。但看来你应该只使用循环来过滤条目:

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

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

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

一个懒惰的解决方案(但可能不适合你的任务)也可以是:

=array_map("unserialize", array_unique(array_map("serialize", $array)));

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)));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文