Unique Array Function

Description: Similar to array_unique(), but implemented manually.

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;

Enjoyed this post? Share it!


Leave a comment

Your email address will not be published.