|
Posted by Rik on 08/15/06 15:36
Karl Groves wrote:
> I'm looking to make a keyword array.
>
> Let's say I have the following array:
>
> $words = array
>
("foo","lorem","foo","ipsum","bar","foo","dolor","sit","foo","bar","amet","
> lorem");
>
> I'd like to create a new array with the top X words, ordered by
> occurrence In the above example, the new array would be:
> $keywords = array("foo","bar","lorem");
I assum the top X words, ordered _descending_?
$number = 10;//or another if you wish
$top = array_slice(array_keys(rsort(array_count_values($words))),0,$number);
If PHP5 or higher this will be better:
$top =
array_keys(array_slice(rsort(array_count_values($words)),0,$number,true));
Grtz,
--
Rik Wasmus
[Back to original message]
|