Re: array.sorting.php

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

 



On Tue, Sep 4, 2012 at 9:20 PM, John Taylor-Johnston
<jt.johnston@xxxxxxxxxxxxxx> wrote:
>
> Here is my code:
> ---------------snip-------------------
> $mynewstring = "http://foo.com/bigtextfile.txt";;
>
> $words = preg_split('/[[:space:]]+/',$mynewstring);
>
> foreach ($words as $word) {
>     $freq[$word]++;
> }
>
> #natcasesort($freq);
> ksort($freq);
>
> John
>
>
> You can try uksort with a custom compare function.
>
> - Matijn
>
>
> Custom compare function?

Yes, for example:
function insensitive_uksort($a,$b) {
    return strtolower($a)<strtolower($b);
}

or use a function like strnatcasecmp.

you can then call
uksort($array, "insensitive_uksort");
or
uksort($array, "strnatcasecmp");

- 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