This code below basically will count the number of occurrences of a word inside an array.
What I would like to happen now though, is to get $word, assign it as a key to an array, and assign $WordCount[$word] to be its value. So for example, if I get, a word "jump", it will be automatically assigned as the key of an array, and the number of occurrences of the word "jump" ($WordCount[$word]) will be assigned as its value. Any suggestions please?
function Count($text)
{
$text = strtoupper($text);
$WordCount = str_word_count($text, 2);
foreach($WordCount as $word)
{
$WordCount[$word] = isset($WordCount[$word]) ? $WordCount[$word] + 1 : 1;
echo "{$word} has occured {$WordCount[$word]} time(s) in the text <br/>";
}
}