# Sorting an Array

**URL:** <https://forum.kirupa.com/t/sorting-an-array/44728>\
**Category:** flash\
**Created:** [March 7, 2004, 3:03am UTC](https://forum.kirupa.com/t/sorting-an-array/44728 "2004-03-07T03:03:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yeldarb](https://avatars.discourse-cdn.com/v4/letter/y/51bf81/32.png) [@Yeldarb](https://forum.kirupa.com/u/Yeldarb)\
**Post date:** [March 7, 2004, 3:03am UTC](https://forum.kirupa.com/t/sorting-an-array/44728/1 "2004-03-07T03:03:31Z")

</div>

I’m drawing values from a database, and inserting them into an array (formatted how I want them exported. I want to then print out this array in alphabetical order by the names of the entries in the array $array["\*"] = stuff; I want it alphabetized by the value where the \* is \<–

I have read through some stuff on [PHP.net](http://PHP.net) and all I could manage to make it do was reverse the order of the array. Here is the code that I have come up with after reading on [PHP.net](http://PHP.net) for a while. It doesn’t work. Can someone please tell me why?

```php

	$results = mysql_query("SELECT * FROM orders", $myLink);
	while($row = mysql_fetch_row($results)) {
		$theNames["$row[3]"] = "<option value=\"$row[1]\">$row[3], $row[4]</option>
";
	}
	
	arsort($theNames);
	reset($theNames);
	while (list($key, $val) = each($theNames)) {
		echo "$val
";
}

```

Thanks 🙂
