public static function unique($array, $keepKeys = false)
{
if ($keepKeys) {
$array = array_unique($array);
} else {
// This is faster version than the builtin array_unique().
// http://stackoverflow.com/questions/8321620/array-unique-vs-array-flip
// http://php.net/manual/en/function.array-unique.php
$array = array_keys(array_flip($array));
}
return $array;
}
public function testUnique() { $array = array(10, 100, 1231, 10, 600, 20, 40, 1231, 20, 6, 1); isSame(array(10, 100, 1231, 600, 20, 40, 6, 1), Arr::unique($array)); $array = array('hello', 'world', 'this', 'is', 'a', 'test', 'hello', 'is', 'a', 'word'); isSame(array('hello', 'world', 'this', 'is', 'a', 'test', 'word'), Arr::unique($array, false)); $array = array('asd_1' => 'asd', 'asd_2' => 'asd'); isSame(array('asd_1' => 'asd'), Arr::unique($array, true)); }