Nasıl bir dizideki en sık yinelenen öğe bulabilirim?

0 Cevap php

Ne fonksiyonunu getMostFrequentlyOccurringItem() aşağıda oluşturmak için en iyi yaklaşım olacaktır?

//should return "paragraph"
echo getMostFrequentlyOccurringItem(array('line', 'paragraph', 'paragraph'));

//should return "line"
echo getMostFrequentlyOccurringItem(array('wholeNumber', 'line', 'line', 'line'));

//should return null
echo getMostFrequentlyOccurringItem(array('wholeNumber', 'wholeNumber', 'paragraph', 'paragraph'));

//should return "wholeNumber"
echo getMostFrequentlyOccurringItem(array('wholeNumber', '', '', ''));

function getMostFrequentlyOccurringItem($items) {
    //...
}

Answer:

Thanks Adam, here's my finished solution: http://tanguay.info/web/index.php?pg=codeExamples&id=396

0 Cevap