How i can remove duplicate from this string and then produce a comma separated values with single quotes to later use IN('1','2') query.

```
$str=1,1,2,2,2,;

```

And i want this

```
$str ='1','2';

```

This is what i have tried so far.

```
$string = rtrim($str,',');
$result = implode(",", array_unique(explode(',', $string)));
echo'<pre>';print_r($result);

```

produced result:

```
1,2

```