Connecting Tech Pros Worldwide Forums | Help | Site Map

how to sort 2 dimentional array in php

Familiar Sight
 
Join Date: Aug 2008
Posts: 175
#1: Oct 13 '09
Hey all,
I need to sort 2 dimentional array.
My data is in this form

arrayName[0][0] = decimal value say 1
arrayName[1][0] = name say abc
arrayName[0][1] = decimal value say 2
arrayName[1][1] = name say def
arrayName[0][2] = decimal value say 3
arrayName[1][2] = name say xyz
arrayName[0][3] = decimal value say 4
arrayName[1][3] = name say ghi

I need to sort my array by name. is there any sorting method in php which sort my array or any custom solution.?

Kindly help out to sort my issue.

Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,669
#2: Oct 13 '09

re: how to sort 2 dimentional array in php


what about sort()?
____________
Familiar Sight
 
Join Date: Aug 2008
Posts: 175
#3: Oct 13 '09

re: how to sort 2 dimentional array in php


how can i use that funtion in order to sort my array with second index of the array. can you give me an example by writing code here by using my example?
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,669
#4: Oct 13 '09

re: how to sort 2 dimentional array in php


Quote:

Originally Posted by neovantage View Post

can you give me an example by writing code here by using my example?

you should already know that I don’t do that…

but you can have a generic example:
Expand|Select|Wrap|Line Numbers
  1. // pseudo code
  2. foreach (1st-level-array)
  3.     sort(2nd-level-array)
Reply