Revisited - 从数组中删除重复的std对象的最快方法

时间:2016-03-10 06:48:16

标签: php arrays performance

我已经阅读了很多关于从数组中删除重复对象的主题,更重要的是,删除了std类对象。我的问题是,似乎没有一致意见,在进入演出时使用哪种方法更好。大多数问题都是以重复的形式提出来的,主要是这个问题

看起来好像两个流行的方法是array_unique()foreach循环,然后有两三个其他没有提到的方法

不幸的是,我的开发站点是为WordPress设置的,只需要很小的测试安装,所以当涉及更大的数据集时,我无法真正运行有关性能的测试。

让我们举个例子:( 注意: 这只是一个小数组,可以包含数百个标准对象

 Array
(
[0] => stdClass Object
    (
        [term_id] => 1
        [name] => First term
        [slug] => first-term
        [term_group] => 0
        [term_taxonomy_id] => 1
        [taxonomy] => category
        [description] => This is the first term
        [parent] => 0
        [count] => 2
    )

[1] => stdClass Object
    (
        [term_id] => 2
        [name] => Second Term
        [slug] => second-term
        [term_group] => 0
        [term_taxonomy_id] => 2
        [taxonomy] => category
        [description] => 
        [parent] => 0
        [count] => 2
    )

[2] => stdClass Object
    (
        [term_id] => 1
        [name] => First term
        [slug] => first-term
        [term_group] => 0
        [term_taxonomy_id] => 1
        [taxonomy] => category
        [description] => This is the first term
        [parent] => 0
        [count] => 2
    )

[3] => stdClass Object
    (
        [term_id] => 2
        [name] => Second Term
        [slug] => second-term
        [term_group] => 0
        [term_taxonomy_id] => 2
        [taxonomy] => category
        [description] => 
        [parent] => 0
        [count] => 2
    )

)

基于上面的链接问题,一般情况下,基于性能和资源管理,这将是删除重复项的最佳选择

0 个答案:

没有答案