Is there a better (faster) solution to remove duplicates from a comma separated string?
public function d($dep) {
if (strpos($dep,\',\') !== false) {
I would probably use the same kind of idea that what you posted ; but I think you can remove your two conditions, to use only this :
$exploded = explode(',', $str);
$unique = array_unique($exploded);
$imploded = implode(',', $unique);
var_dump($imploded);
I've tested it with those three strings, and it seems to work in each case :
$str = 'a,b,c,d,a,c,e,f';
$str = 'a,a';
$str = 'a';
Notes :
Of course, you can also remove the variables, and use only one line :
$result = implode(',', array_unique(explode(',', $str)));
Not sure it's easier to understand that way, though...