[slang-users] iterate the elements of an assoc_array in sorted order

John E. Davis davis at space.mit.edu
Sat Jun 3 18:57:16 EDT 2006


Jörg Sommer <joerg at alea.gnuu.de> wrote:
>how is it possible to iterate through an Assoc_Array in sorted order.
>This is ugly:
>
>foreach ( assoc_get_keys(templates)[array_sort(assoc_get_keys(templates))] )

You will have to perform a sort as you have done.  I would write the
above as

    keys = assoc_get_keys (templates);
    foreach k (keys[array_sort(keys)]) {...}

which I find somewhat more readable.

--John
    
    




More information about the slang-users-l mailing list