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.


Post a Comment



We use third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you.