Jump to content

Remove duplicate in string


drisate

Recommended Posts

Hey guys i have a string that looks like this

 

-3--3--3--3--3--3--3--3--3--3--10--10--10--10--10--10--10--10--10--10--7--7--7--7--7--7--7--7--7--7--12--12--12--12--12--12--12--12--12--12--1--1--1--1--1--1--1--1--1--1--19--19-

 

How can i remove the duplicates so it looks like

 

-3--10--7--12--1--19-

 

It needs to be fast because there will be a lot of strings to be checked

Link to comment
https://forums.phpfreaks.com/topic/200891-remove-duplicate-in-string/
Share on other sites

Thx this is what i did for future ref

 

          $list3 = implode("-" , array_unique(explode("-",$bouton[bouton])));

          $ex = explode ('-', $list3);

          foreach($ex as $value){

            if ($value){

                $string .= "-$value-";

            }

          }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.