473,508 Members | 2,130 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1985
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
15559
by: ubccis | last post by:
Hi. Does for each for on multidimensional arrays? For example, if one element of $in is $course_list and I want to echo all everything in course_list
5
1924
by: TheKeith | last post by:
I can't figure out why this doesn't work: --------------------------------------------- greeting = new Array(); greeting = "hey"; greeting = "bye"; trace(greeting + greeting);
1
1776
by: Durior | last post by:
A colleague has just showed me the syntax that introduces multidimensional arrays (as opposed to jagged arrays, which are similar to C++ arrays). So we defined such an array: int a= new...
3
1098
by: dotNETnews | last post by:
I understand what are 1 and 2 Dimensional Arrays but I have some problems understanding 3 and more dimensional Arrays. If you know a good article, let me know. Thnaks.
21
4152
by: utab | last post by:
Hi there, Is there a way to convert a double value to a string. I know that there is fcvt() but I think this function is not a part of the standard library. I want sth from the standard if...
10
12165
by: | last post by:
I'm fairly new to ASP and must admit its proving a lot more unnecessarily complicated than the other languages I know. I feel this is because there aren't many good official resources out there to...
2
4553
by: Nathan Sokalski | last post by:
I have a multidimensional array declared as the following: Dim guesses(14, 5) As Integer I want to assign all values in a specific dimension to another array declared as follows:
8
2160
by: ajayicon | last post by:
Hi all, I am not an expert in C..more of an algorithm developer. One of my algorithm requires use of multidimensional struct. for example something like: struct cell{ int row; ...
9
4473
by: Slain | last post by:
I need to convert a an array to a multidimensional one. Since I need to wrok with existing code, I need to modify a declaration which looks like this In the .h file int *x; in a initialize...
0
7123
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7326
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7498
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5627
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.