php去除重復(fù)字的實現(xiàn)代碼
更新時間:2011年09月16日 17:11:32 作者:
php去除重復(fù)字的實現(xiàn)代碼,需要的朋友可以參考下。
方法一:
$text = '數(shù)組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;
方法二:
$string= '數(shù)組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)));
方法三:
就是把每一個字分割在數(shù)組里再用array_unique()這個函數(shù)。
復(fù)制代碼 代碼如下:
$text = '數(shù)組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;
方法二:
復(fù)制代碼 代碼如下:
$string= '數(shù)組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)));
方法三:
就是把每一個字分割在數(shù)組里再用array_unique()這個函數(shù)。
您可能感興趣的文章:
- php從數(shù)組中隨機選擇若干不重復(fù)元素的方法
- PHP查找數(shù)值數(shù)組中不重復(fù)最大和最小的10個數(shù)的方法
- php數(shù)組函數(shù)序列之a(chǎn)rray_unique() - 去除數(shù)組中重復(fù)的元素值
- php array_flip() 刪除數(shù)組重復(fù)元素
- PHP n個不重復(fù)的隨機數(shù)生成代碼
- php二維數(shù)組合并及去重復(fù)的方法
- PHP兩種去掉數(shù)組重復(fù)值的方法比較
- PHP去除數(shù)組中重復(fù)的元素并按鍵名排序函數(shù)
- php去除數(shù)組中重復(fù)數(shù)據(jù)
- PHP獲取字符流中第一個不重復(fù)字符的方法
相關(guān)文章
php中 ob_start等函數(shù)截取標(biāo)準(zhǔn)輸出的方法
這篇文章主要介紹了php中 ob_start等函數(shù)截取標(biāo)準(zhǔn)輸出的方法的相關(guān)資料,需要的朋友可以參考下2015-06-06php判斷輸入不超過mysql的varchar字段的長度范圍
varchar類型字段,如果你設(shè)置長度為10,那么不論漢字和英文都可以存10個。2011-06-06Admin generator, filters and I18n
You need to modify your EntityFormFilter (where Entity is your object class - Article, Book, etc.).2011-10-10php+jQuery+Ajax實現(xiàn)點贊效果的方法(附源碼下載)
這篇文章主要介紹了php+jQuery+Ajax實現(xiàn)點贊效果的方法,結(jié)合實例形式詳細介紹了php結(jié)合jQuery的ajax無刷新提交實現(xiàn)點贊功能的具體步驟與相關(guān)技巧,需要的朋友可以參考下2015-12-12