Serge Fonville wrote:
Have you looked at http://php.net/manual/en/array.sorting.php?

2012/9/3 John Taylor-Johnston <jt.johns...@usherbrooke.ca <mailto:jt.johns...@usherbrooke.ca>>


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

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

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

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

        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

    I'm fuzzy when it comes to arrays. I never get what I want right.

    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
    )


I'm beginning to think I should plug this into a MySQL table, where I would be at home. But right now, I'll be stubborn and go read http://php.net/manual/en/array.sorting.php.
Merci Serge,
John

Reply via email to