Remove duplicate from string

I beginner in php.

I have this code:

$string = '["Rumia","Rumia","Joarilla de las Matas","Rumia"]';

How can I remove duplicate from this string?

I build this string by this code:

$res = app('geocoder')->geocode($request->input('city'))->get();
foreach ($res as $value) {
if($formatter->format($value, '%L') !=""){
$string .= '"'.$formatter->format($value, '%L').'"'. ",";
}
}

if (strlen($string) > 0){
$string = mb_substr($string, 0, -1);
echo "[".$string."]";
}
array_unique($string); //this is for an array,

$new_var = implode(',',array_unique(explode(',', $string))); //this is for a string

printf(" The Final String after Removing All Duplicates = %s ", str); C Program to Remove All Duplicate Character in a String Example 2. This program is the same as above. Here, we just replaced the For Loop with While Loop.

This "string" is an array. Then you could use the array_unique function like this:

array_unique($string);

It will return an array with only unique values.

Remove all consecutive duplicates from the string Given a string S, remove all the consecutive duplicates. Note that this problem is different from Recursively remove all adjacent duplicates. Here we keep one character and remove all subsequent same characters.

Try This:

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

Simple solution is to iterate through the given string and put each unique character into another string(in this case, a variable result) if this string doesn't contain that particular character.Finally return result string as output.

Given a string S of lowercase letters, a duplicate removal consists of choosing two adjacent and equal letters, and removing them. We repeatedly make duplicate removals on S until we no longer can. Return the final string after all such duplicate removals have been made. It is guaranteed the answer is unique.

Java String array remove duplicates example 1) Java String array remove duplicates using Set (HashSet/LinkedHashSet) One of the properties of the Set is that it 2) Using an ArrayList We can also use the ArrayList class to remove the duplicates as given below. 3) Using Java 8 Stream

Remove all duplicates from a given string in Python; Remove three consecutive duplicates from string; Remove duplicates from string keeping the order according to last occurrences; Reverse individual words with O(1) extra space; Recursively remove all adjacent duplicates; Python groupby method to remove all consecutive duplicates; Find one extra character in a string; Balance a string after removing extra brackets; Print all the duplicates in the input string