I'm trying to find the most used word in a string in PHP. The lyrics file is a string of lyrics.
//display the most used word in the lyrics file
$wordCount = str_word_count($lyrics);
$wordCountArray = array();
foreach($wordCount as $word){
if(!array_key_exists($word, $wordCountArray)){
$wordCountArray[$word] = 1;
}else{
$wordCountArray[$word] += 1;
}
}
arsort($wordCountArray);
print_r($wordCountArray[0]);
I'm getting errors with this code and I'm wondering what isn't working. I need the actual word and not the number.