Some tips.
1. Remove duplicates in array using array_unique
array array_unique ( array $array [, int $sort_flags = SORT_STRING ] )
2. Remove empty elements use array_filter
array array_filter ( array $array [, callable $callback [, int $flag = 0 ]] )
3. value is in the array use in_array
bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )
4. key exist in array use array_key_exist
bool array_key_exists ( mixed $key , array $array )