Home > Bookmarks, PhP, Tech, Web > PHP: array_unique without gap !

PHP: array_unique without gap !

If you use array_unique function for getting unique values in a simple array and if you need the index to be linear use this :

$unique = array_keys(array_flip($array));

This metod is about twice as fast or fast as array_unique !

Note that array_unique preserves the keys, even if the array is not associative.

  1. No comments yet.
  1. No trackbacks yet.
GoCache - ByREV-Cache v1.0 - live served in : 0.148859 sec (gzip)