Answer the question
In order to leave comments, you need to log in
How to display the most popular words from an array?
php. There is a large array that I got by splitting a long string into words. Now you need to display the 20 most popular words that are most often found in the same array (string).
How to do it?
Answer the question
In order to leave comments, you need to log in
<?php
$array = array(1, "hello", 1, "world", "hello");
$counter = array_count_values($array);
arsort($counter);
print_r(array_slice($counter,0,20));
?>
Array
(
[1] => 2
[hello] => 2
[world] => 1
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question