php 提取數組中重複的數據


提取數組中的重複數據


function FetchRepeatMemberInArray($array){ 
	// 獲取去掉重複數據的數組 
	$unique_arr = array_unique ( $array ); 
	// 獲取重複數據的數組 
	$repeat_arr = array_diff_assoc ( $array, $unique_arr ); 
	return $repeat_arr; 
} 

$array = array ( 
'apple', 
'iphone', 
'miui', 
'apple', 
'orange', 
'orange' 
);

//$array = explode(",", $str1);
//print_r($array);exit;
$repeat_arr = FetchRepeatMemberInArray ( $array ); 
echo '<pre>';
print_r ( $repeat_arr ); 
echo '</pre>';


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章