How to sort an array alphabetically

Hi, I need a simple solution to sort an array alphabetically, here is my code:

    <?php while(sort($cities=dbFetchArray($results)))
                   {?>
					 <option value="<?=$cities['grd']?>"> <?=$cities['grd']?></option>
                      <?php }?>                         

As you can see I added the sort function, but doesnt work… any ideas?

I found this, at the top of the list, of a quick Google search: http://www.w3schools.com/php/func_array_sort.asp
Even the example sorts a set of strings alphabetically.

hi thanks for that… as you can see I added the sort function … but it doesn’t seem to sort alphabetically… what I am doing wrong?

You’re trying to do too much in one line. Make your while pull the array, then sort it inside the loop.

Since you are pulling from the database make the database do the sorting with an ORDER BY clause.


SELECT grd FROM cities ORDER BY grd DESC

Under normal circumstances SQL can sort considerably faster than PHP, so it is more efficient to use SQL ordering at query time.