What's the right way to sort a associated array in bash or zsh?

view story

http://unix.stackexchange.com – I'm wondering how should I sort the associated array in bash? I tried the manual, but seems nothing related to sort. The current solution is echo everything out, and use external program i.e key value | sort -k2 That looks inefficient to me. An example of array was: A[''] = 5 A[''] = 1 A[''] = 9 And I'll be looking for the top 2 used IP address, which is and, that is, I need to sort this array by it's value. (HowTos)