How to remove duplicate characters in PHP?

Guanhui
Release: 2023-03-02 21:56:01
Original
3180 people have browsed it

How to remove duplicate characters in PHP?

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);
Copy after login

Other methods

/* 4.$m = “woxihuanphp”,编程实现:将字符串分割为单个字符存放到一个数组中,并打印数组? */ $m='woxihuanphp'; echo $res=trim(chunk_split($m,1,'.'),'.'); $arr1=explode('.',$res); var_dump($arr1);
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!