ksort by value

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

<?php
...
$words = preg_split('/[[:space:]]+/',$mynewstring);

foreach ($words as $word) {
    $freq[$word]++;
}

ksort($freq);
print_r ($freq);
?>

If I have my terminology right, ksort($freq) sorts the array by the key. And that works fine.
But I would also like to sort by value to see which words are more frequent.
There is no |ascending/descending option to ksort?|

Thanks,
John

Array
(
    [] => 1
    [a] => 165
    [about] => 4
    [academy] => 4
    [accident] => 3
    [accidental] => 1
    [accused] => 1
    [achieve] => 1
    [across] => 1
    [act] => 3
    [addition] => 1
    [address] => 1
    [adult] => 3
    [advise] => 2
    [advised] => 1
    [advising] => 2
    [advisory] => 4
    [after] => 2
    [aged] => 1
    [aggravated] => 1
    [airport] => 4
    [alarm] => 2
    [alcohol] => 5
    [alert] => 1
    [all] => 2
    [allegedly] => 2
    [allow] => 1
    [along] => 2
    [also] => 14
    [altercation] => 2
    [am] => 16




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux