2013-06-19 3 views
0

나는 단어배열의 중복 수를 계산 하시겠습니까?

(“hello”, “apple”, “hello”, “hello”, “apple”, “orange”, “cake”) 

Result here should be 5

다음과 같은 배열의 접촉을 내 배열에 존재 얼마나 많은 중복 단어를 계산하는 데 사용할 수있는 PHP에서 라이브러리 함수가있는 경우 당신이 말해 주시겠습니까? 어떤 도움이라도 대단히 감사하겠습니다.

+0

array_count_values가 detaied 정보를 여러분 모두 감사합니다. 그들 모두는 매우 도움이되었다 –

답변

0
$array = array(“hello”, “apple”, “hello”, “hello”, “apple”, “orange”, “cake”); 
$unique_elements = array_unique($array); 
$totalUniqueElements = count($unique_elements); 
echo $totalUniqueElements; 
//Output 5 

Hope this will help you. 
+0

@nickb 내 텍스트 형식을 개선해 주셔서 감사합니다. –

0

당신이 할 수있는이

$count1 = count($array); 
$count2 = count(array_unique($array)); 
echo $count1 - $count2; 
+0

미안하지만 나는 그가 유일한 카운트가 필요하다고 생각했다 .... 내 ans을 업데이트했다. – Gautam3164

0

같은 시도 :

$org = count($array); 
$unique = count(array_unique($array)); 
$duplicates = $org - $unique 
관련 문제