Home >Backend Development >PHP Tutorial >pretty dear rhythm my future php implementation code for removing duplicate words

pretty dear rhythm my future php implementation code for removing duplicate words

WBOY
WBOYOriginal
2016-07-29 08:46:47891browse

Method 1:

Copy the code The code is as follows:


$text = 'array aabbccdd';
$text_filter = '';
$filter = array();
$len = mb_strlen($text, ' utf-8');
for ($i = 0; $i<$len; $i++) {
$char = mb_substr($text, $i, 1, 'utf-8');
if (!isset ($filter[$char])) {
$text_filter .= $char;
$filter[$char] = $char;
}
}
echo $text_filter;


Method 2:

Copy code The code is as follows:


$string= 'array aabbccdd';
function str_split_utf8($str) {
$split=1;
$array = array();
for ( $i=0; $i < strlen( $str ); ){
$value = ord($str[$i]);
if($value > 127){
if($value >= 192 && $value <= 223)
$split=2;
elseif($value >= 224 && $value <= 239)
$split=3;
elseif($value >= 240 && $value <= 247)
$split=4 ;
}else{
$split=1;
}
$key = NULL;
for ( $j = 0; $j < $split; $j++, $i++ ) {
$key .= $str[$ i];
}
array_push( $array, $key );
}
return $array;
}
print_r(array_unique(str_split_utf8($string)));


Method 3:
Is to split each word Use the array_unique() function in the array again.

The above introduces the implementation code of pretty rhythm dear my future PHP to remove duplicate words, including the content of pretty rhythm dear my future. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
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