note 70786 modified in function.array-unique by danbrown
| From: | danbrown@php.net | Date: | Thu, 06 Nov 2008 14:55:41 +0000 |
| Subject: | note 70786 modified in function.array-unique by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-146219@lists.php.net to get a copy of this message | ||
For people looking at the flip flip method for getting unique values in a simple array. This is the
absolute fastest method:
<?php
$unique = array_keys(array_flip($array));
?>
It's marginally faster as:
<?php
$unique = array_merge(array_flip(array_flip($array)));
?>
And it's marginally slower as:
<?php
$unique array_flip(array_flip($array)); // leaves gaps
?>
It's still about twice as fast or fast as array_unique.
This tested on several different machines with 100000 random arrays. All machines used a version of
PHP5.
--was--
For people looking at the flip flip method for getting unique values in a simple array. This is the
absolute fastest method:
$unique = array_keys(array_flip($array));
It's marginally faster as $unique = array_merge(array_flip(array_flip($array)));
And it's marginally slower as $unique array_flip(array_flip($array)) which leaves gaps.
It's still about twice as fast or fast as array_unique.
This tested on several different machines with 100000 random arrays. All machines used a version of
PHP5.
http://php.net/manual/en/function.array-unique.php