I have been working on a script that pulls testimonials from a database, adds each result to an array and then counts the number of times each word occurs in the entire array.
This works fine but what I need to do now is grab that array and loop though it to display the top 10 words that occur in my array. I'm not sure of the most efficient way to do this...
Here is my existing code
$result = mysql_query("SELECT testimonial FROM testimonials WHERE active = 1") or die(mysql_error());
$testimonials = array();
if(mysql_num_rows($result)) {
while($row = mysql_fetch_array($result)) {
array_push($testimonials, $row['testimonial']);
}
};
$rawstring = implode(" ", $testimonials);
$words = (array_count_values(str_word_count($rawstring, 1)));
Any help would be appreciated.