function d($dep) {
return implode(',', array_keys(array_flip(explode(',', $dep))));
}
array_flip swaps the key-value association, so the values become the keys and vice versa. This will automatically eliminate duplicates. Its runtime complexity is O(n).