Re: Sorting an array

From: Date: Tue, 01 Mar 2011 05:25:04 +0000
Subject: Re: Sorting an array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-311599@lists.php.net to get a copy of this message
On 1/03/2011, at 4:52 PM, Ron Piggott wrote: > > I need help to know how to sort the words / phrases in my array. > > Variable name: $words_used > print_r( $words_used ); Current output: Array ( [187] => Sin [249] => Punished [98] => > Sanctuary [596] => Sing [362] => Anointing Oil ) > Desired result: Alphabetical sort: Array ( [362] => Anointing Oil [249] => Punished [98] > => Sanctuary [187] => Sin [596] => Sing ) > > The #’s are the auto_increment value of the word in the mySQL database. The number is not > representative of alphabetical order, but the order it was added to the database. > > Thank you for your assistance. > > Ron > > The Verse of the Day > “Encouragement from God’s Word” > http://www.TheVerseOfTheDay.info Have a look at asort() (http://php.net/asort), which is used to sort arrays but maintain the key association. The default search option should work fine for you, if not try one of the other SORT_* flags described on the sort() manual page. --- Simon Welsh Admin of http://simon.geek.nz/ Who said Microsoft never created a bug-free program? The blue screen never, ever crashes! http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e

« previous php.general (#311599) next »