How to remove duplicate characters in PHP?
First use the "explode()" function to break up the string into an array; then use the "array_unique()" function to remove duplicate elements from the array; finally use the "implode()" function to Arrays can be composed into strings.
Sample code
$str = '1.2.3.1.2.3.4.5.6.7.8.9'; //拆分为数组 $arr = explode('.', $str); //去除重复字符 $arr = array_unique($arr); //组成字符串 $str = implode('.', $arr);
Other methods
/* 4.$m = “woxihuanphp”,编程实现:将字符串分割为单个字符存放到一个数组中,并打印数组? */ $m='woxihuanphp'; echo $res=trim(chunk_split($m,1,'.'),'.'); $arr1=explode('.',$res); var_dump($arr1);
Recommended tutorial: "PHP"
The above is the detailed content of How to remove duplicate characters in PHP?. For more information, please follow other related articles on the PHP Chinese website!