Method: 1. Use the explode() function to split the specified field into an array; 2. Use the "array_unique" function to remove duplicate values in the array; 3. Use the implode() function to remove duplicate values from the array. Just combine it into a string.
The operating environment of this tutorial: windows10 system, PHP7.1 version, DELL G3 computer
php a field value How to remove duplicate values
explode(',',$data) splits the string into an array
array_unique() removes duplicate values from the array
implode(',',$data))) Use, to split and combine the array into a string
The example is as follows:
$data = "xiaomi,xiaohong,xiaogang,xiaomi,xiaohu"; $data = implode(',',array_unique(explode(',',$data))); echo $data;
//The result is $data="xiaomi, xiaohong,xiaogang,xiaohu";
If you are interested, you can click on "PHP Video Tutorial" to learn more about PHP knowledge.
The above is the detailed content of How to remove duplicate values from a field value in PHP. For more information, please follow other related articles on the PHP Chinese website!