I'm reading some code ... (full disclaimer, MINE ):
foreach ($list as $item) {
if (preg_match($some_regexp,$item,$matched)) {
$key = $matched[1];
$some_array[$key] = $item;
}
}
//this is necessary?
$some_array = array_unique($some_array);
It looks as if the array is constructed in such a way that its keys (and by extension, values*) will be unique be default. Can anyone think of any case where it would NOT be unique? Can I chuck the array_unique() call? It looks pretty danged expensive....
All my testing says "yeah, take out the expensive call". I'm just not trusting my brain this week, I guess. Ouch....
(* this can't be proven in the abstract ... or logically, without knowledge of the data set. However, I have that knowledge and the data will be unique IF the key is ... )