470,862 Members | 1,855 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,862 developers. It's quick & easy.

Sorting multidimensional arrays on a named dimension??

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
Jul 17 '05 #1
2 1900
"markus" <m7***@hotpop.com> wrote in message
news:b2**************************@posting.google.c om...
I usually store info in arrays using field names

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

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


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

http://us3.php.net/manual/en/function.sort.php

Chris Finke
Jul 17 '05 #2
markus wrote:
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)


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

http://www.php.net/manual/en/function.usort.php

Example 2.
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by ubccis | last post: by
5 posts views Thread by TheKeith | last post: by
3 posts views Thread by dotNETnews | last post: by
21 posts views Thread by utab | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.