Home >> Snippet List >> Snippet

Name
Unique Array function
Description
Similar to array_unique(), but implemented manually
PHP Snippet
<?PHP
 
FUNCTION uniqueArray($array)
{
// Get unique elts as keys in assoc. array
FOR ($i=0,$n=COUNT($array, 1);$i<$n;$i++)
     $u_array[$array[$i]] = 1;
 
// Copy keys only into another array
RESET($u_array, 1);
FOR ($i=0,$n=COUNT($u_array, 1);$i<$n;$i++) {
     $unduplicated_array[] = KEY($u_array, 1);
     NEXT($u_array, 1);
}
RETURN $unduplicated_array;
}
 
?>