remove duplicate from string in PHP -
i looking fastest way remove duplicate values in string separated commas.
so string looks this;
$str = 'one,two,one,five,seven,bag,tea';
i can exploding string values , compare, think slow. preg_replace() faster? 1 did using function?
the shortest code be:
$str = implode(',',array_unique(explode(',', $str)));
if fastest... don't know, faster looping explicitly.
reference: implode
, array_unique
, explode
php string duplicates
No comments:
Post a Comment