Re: ksort by value

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

 



That works, thanks.
I think I'll put this into MySQL eventually. "sort by" key would do it better, and I will need to more.

Serge Fonville wrote:
Sort does not maintain the association between key and value. Use asort to sort on value while maintaining the key.

Kind regards/met vriendelijke groet,

Serge Fonville

http://www.sergefonville.nl

Convince Microsoft!
They need to add TRUNCATE PARTITION in SQL Server
https://connect.microsoft.com/SQLServer/feedback/details/417926/truncate-partition-of-partitioned-table



2012/9/3 John Taylor-Johnston <jt.johnston@xxxxxxxxxxxxxx <mailto:jt.johnston@xxxxxxxxxxxxxx>>


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

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

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


        Sort does not work seamlessly. I have my key and
        sort($freq);
        print_r ($freq);
        looks like:

        Array
        (
            ...
            [1000] => 172
            [1001] => 176
            [1002] => 179
            [1003] => 441
        )

        This is what I want:

        Array
        (
            ...
            [and] => 172
            [of] => 176
            [to] => 179
            [the] => 441

        )


    http://php.net/manual/en/array.sorting.php is pretty clear. But my
    problem is that sort ($freq) destroyed my key.





[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