Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sort multidimensional array

Status
Not open for further replies.

richardko

Programmer
Jun 20, 2006
127
US
hi,
I have a multidimensional array like this:
arr['name'],arr['age'],arr['salary'].

If i need to sort this array by 'age' how would I do it?
thanks
 
that's funny. i replied to this thread hours ago, never got posted!

for array_multisort you would need to restructure your array. if you were going to this effort then it would be better (with your current structure) to create a new array of ages and unique ids (use the ids as the key), sort the new array the iterate over it to recompile the original array.

by far the best way is to do the array sorting implicitly in the sql query from which you retrieve the data (use and ORDER BY clause). then as you iterate over the recordset the data will be presorted.
 
thedaver, thanks for the documentation. I had looked at the documentation before but it was little fuzzy on how to restructure the data.
jpadie, I love your suggestion but I am accessing multiple tables and also i am rearranging the data as they come in. The table i gave was just an example. Thanks for your tip.
I will try it again with the documentation
thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top