In PHP, how do I deduplicate strings with built-in functions?

In PHP, you can easily deduplicate strings using built-in functions. One of the most common ways to achieve this is by using the `array_unique()` function to remove duplicate values from an array after splitting a string into an array using `explode()`. Here’s a simple example:

<?php $string = "apple,banana,apple,orange,banana"; $array = explode(",", $string); // Split the string into an array $uniqueArray = array_unique($array); // Remove duplicates $resultString = implode(",", $uniqueArray); // Convert array back to string echo $resultString; // Outputs: apple,banana,orange ?>

deduplicate strings PHP array_unique explode