Sorting multidimensional arrays on a named dimension??

Sorting multidimensional arrays on a named dimension??

Post by m748 » Thu, 22 Jul 2004 10:00:36


I usually store info in arrays using field names

$array[1]["country"]='Germany',
$array[1]["code"]="GE";

$array[2]["country"]='United Sates"
$array[2]["code"]="US";

$array[3]["country"]='France"
$array[3]["code"]='FR"

I want to get:
$array[1]["country"]='France"
$array[1]["code"]='FR"

$array[2]["country"]='Germany'
$array[2]["code"]="GE";

$array[3]["country"]='US"
$array[3]["code"]="US";

Is there a function to sort on a field (country in this case)

thanks
 
 
 

Sorting multidimensional arrays on a named dimension??

Post by Christophe » Thu, 22 Jul 2004 10:11:02


Read the PHP.net page on the sort() function. There are several
multidimensional sort functions in the user-submitted comments at the
bottom:

http://www.yqcomputer.com/

Chris Finke

 
 
 

Sorting multidimensional arrays on a named dimension??

Post by Zurab Davi » Thu, 22 Jul 2004 10:15:01


Yes (as in you can use user-defined function for sorting):

http://www.yqcomputer.com/

Example 2.