I have an function that creates an array of words from a string, counts how often each word occurs and then selects the top 21 words.
Trouble I'm having is I then need to shuffle those 21 words. If I try shuffle() my foreach loop will output the number of occurences rather than the word itself.
Can someone show me how to do this? Here is my existing function:
$rawstring = implode(" ", $testimonials);
$rawstring = filterBadWords($rawstring);
// get the word=>count array
$words = array_count_values(str_word_count($rawstring, 1));
// sort on the value (word count) in descending order
arsort($words);
// get the top frequent words
$top10words = array_slice($words, 0, 21);
shuffle($top10words);
foreach($top10words as $word => $value) {
$class = getClass($value);
echo "<a href=\"#\" id=\"" . $word . "\" class=\"" . $class . "\">" . $word . "</a>";
}