Question: i have a php string 

```
$select_columms = 'pid, p.title, caption, filepath, filename, encaption, user1, user2, user3, user4, user5, user6, ult_puja, p.title, user2, user3';

```

so i had this idea i could get a unique string with this line of code

```
$select_columns = implode(',', array_unique(array_filter(explode(',',$select_columns))));

```

but it doesn't seem to work can you see what i am missing?

*edit:*
*thanks* for the help my final code is:

```
$select_columns = implode(',', array_filter(array_unique(explode(',', $select_columns))));

```

which outputs `$select_columns = 'pid, p.title, caption, filepath, filename, encaption, user1, user2, user3, user4, user5, user6, ult_puja'`

i use the array\_filter in case i have input like `', pid,'`

Answer: 
Try this out 

```
echo implode(',', array_unique(explode(',', $select_columms)));

```

**EDIT** As @amitchd pointed out. Fails hard when not trimmed. Fixed now

And if your string has uneven spacing, you can do this 

```
$select_columms = 'pid, p.title, caption, filepath, filename, encaption, user1, user2, user3, user4, user5, user6, ult_puja, p.title, user2, user3';
$arr    = explode(',', $select_columms);
array_walk($arr, '_trim');
echo implode(',', array_unique($arr));

function _trim(&$value) {
    $value = trim($value);   
}

```
```
$str = implode(',',array_unique(explode(',', $str)));

```