note 116363 modified in function.array-unique by tularis
| From: | tularis@php.net | Date: | Fri, 19 Dec 2014 14:10:45 +0000 |
| Subject: | note 116363 modified in function.array-unique by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-201226@lists.php.net to get a copy of this message | ||
[Editor's note: please note that this will not work well with non-scalar values in the array.
Array keys can not be arrays themselves, nor streams, resources, etc. Flipping the array causes a
change in key-name]
You can do a super fast version of array_unique directly in PHP, even faster than the other solution
posted in the comments!
Compared to the built in function it is 20x faster! (2x faster than the solution in the comments).
<?php
function superfast_array_unique($array) {
return array_keys(array_flip($array));
}
?>
This works faster for small and big arrays.
--was--
You can do a super fast version of array_unique directly in PHP, even faster than the other solution
posted in the comments!
Compared to the built in function it is 20x faster! (2x faster than the solution in the comments).
<?php
function superfast_array_unique($array) {
return array_keys(array_flip($array));
}
?>
This works faster for small and big arrays.
http://php.net/manual/en/function.array-unique.php