Re: ksort by value

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

 



On Mon, Sep 3, 2012 at 8:33 PM, John Taylor-Johnston
<jt.johnston@xxxxxxxxxxxxxx> wrote:
> 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

ksort sorts by key, if you want by value, look at sort.
As to asc/desc sort, they just have a different name. ksort and sort
are asc, krsort and rsort are desc equivalents.

- Matijn

-- 
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