php - Nasıl bir dizide öğelerin tekrarlarını saymak

1 Cevap php

Bu dizi çekmek:

Array ( [#twitterwhites] => 0 [#lufc] => 0 [#FOOTBALL] => 0 [#Liverpool] => 0 [#liverpool] => 0 [#ESPN] => 0 [#LUFC] => 0 [#cafc] => 0 [#cafc] => 0 [#ocra] => 0 [#nra] => 0 [#2nd] => 0 [#secondamendment] => 0 [#SCR] => 0 [#TC500] => 0 [#cpfc] => 0 [#MOT] => 0 ) 

Ben böyle bir sonuca dönmek istiyorum:

#liverpool = 2

#cafc = 2

#LUFC = 1  

ETC ETC

Ben bunu nasıl yaparım?

1 Cevap

Bunu sadece values sayar gibi, dizi değişiklikler biraz ile, array_count_values() işlevini kullanmak değil, keys olabilir .

(As suggested in a comment to your question, anyway, you cannot have the same key several times in an array -- which means your array probably already has your items as values, and not keys)