remove duplicate from string in PHP

Posted by Adnan on Stack Overflow See other posts from Stack Overflow or by Adnan
Published on 2010-04-10T10:39:51Z Indexed on 2010/04/10 10:43 UTC
Read the original article Hit count: 159

Filed under:
|
|

Hello,

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,seven,bag,tea';

I can do it be exploding the string to values and then compare, but I think it will be slow. what about preg_replace() will it be faster? Any one did it using this function?

© Stack Overflow or respective owner

Related posts about php

Related posts about string