NogDog;11043299 wrote:If you want to make sure the source array has unique values:
foreach(array_keys(array_flip($list)) as $item) {
Could be faster as no sorting is involved -- to keep in mind in case you actually want the sorting side-effect of array_unique().
It's not really necessary to sort. That's a cool thing that might work. However, wouldn't it also have some expense? We're talking about an array of multiple tens of thousands of strings ... if I can be reasonably sure that the assignment will eliminate duplicates, I'd like to just do the assignment and go on.
Weedpacket wrote:Is there or was there a circumstance where $some_array is not empty before the loop?
No.
(And I can see an argument for claiming that if the key is unique then so is the value: the key is part of the value - if given two items the same regex finds different keys, then the items themselves must be different.)
That's kind of, I think, what I'm assuming. These are lists of URLs, constructed something like this:
site.com/meaningful_search_term_combination_related_to_content_detail_12345.html
I'm extracting the numeric part (12345 in the example) to be the key. As near as I can tell, these URLs are created by mod_rewrite, and it's actually passing "12345" to the script as a page ID. I have found differing "meaningful_search_term" strings with the same numeric code (and therefore the same page content), and I'm trying to avoid duplicates as a result.
I'm fairly confident this will work unless we can prove otherwise here. Thanks for your time, guys. 🙂