Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove duplicate words from string using php? [duplicate]

Below is the variable I have,

$string = 'AAA,BBB,aAA,BbB,AAA,BbB';

I need the unique string result below,

$string = 'AAA,BBB,aAA,BbB';

How to make it unique just like array_unique() function , is there any default String function to remove duplicate string in PHP?

like image 791
Thiyagu Avatar asked Dec 13 '22 23:12

Thiyagu


1 Answers

I don't know if php have such function, but you can process it like this: live demo

$raw = 'AAA,BBB,aAA,BbB,AAA,BbB';
$string = implode(',', array_unique(explode(',', $raw)));
like image 141
LF00 Avatar answered Mar 06 '23 00:03

LF00