Exclude repeated values from a variable

3

I'll just give you a simpler example so I do not have to post the whole code, I do not know if that's possible.

$exemplo = "exemplo exemplo"

echo $exemplo;

When displaying this variable with echo it returns "example example", would it have any command or something it can use to return it only "example" without repeating the word?

Note: I can not change the value of the variable nor why, since the way I use it to capture it returns me exactly as it is above.

    
asked by anonymous 26.04.2016 / 20:15

1 answer

6

You can transform into an array using implode() and then use array_unique() to remove all duplicate words, and then return the normal string using implode() .

Example:

$exemplo = "exemplo exemplo exemplo exemplo";
$exemplo = implode(" ", array_unique(explode(" ", $exemplo)));
echo $exemplo; // Saida  = "exemplo"
    
26.04.2016 / 20:23