I have read up on quite a few topics regarding removing duplicate objects from an array, more so, removing std class objects. My issue is, there seems to be no concensus about which is the better method to use when coming to performance. Most of the questions asked where closed as duplicates, mainlt to this one
It does look like the two popular methods are array_unique()
and a foreach
loop, and then there are two or three other not so much mentioned methods
Unfortunately, my dev site is set up for WordPress with quite a small test install, so I cannot really run tests regarding performance when it comes to bigger data sets.
Lets take an example: (NOTE: This is just a small array which can contain hundreds of std objects)
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
)
)
Based on the linked question above, and just in general, based on performance and resource management, which would be the best option to remove duplicates