remove duplicate from string in PHP

前端 未结 2 1954
青春惊慌失措
青春惊慌失措 2020-11-27 04:05

I am looking for the fastest way to remove duplicate values in a string separated by commas.

So my string looks like this;

$str = \'one,two,one,five,         


        
2条回答
  •  时光取名叫无心
    2020-11-27 04:30

    The shortest code would be:

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

    If it is the fastest... I don't know, it is probably faster then looping explicitly.

    Reference: implode, array_unique, explode

提交回复
热议问题