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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting Array

Status
Not open for further replies.

alsaffar

Programmer
Oct 25, 2001
165
KW
Hi there,

I have a multi-dimensional array as follow:

$x[1][1]='C';
$x[1][2]='A';
$x[1][3]='B';
$x[2][1]='F';
$x[2][2]='X';
$x[2][3]='D';

How can I sort the array first on $x[][2] then on $x[][3]?
 
I don't know that I follow exactly...

Are you sorting only on values? Then you can just use array_multisort... are you trying to sort by a mix of keys and values? That's maybe a little trickier... but usort should still be useable for it.

Otherwise, you could just write your own sorting function... the built in ones aren't always the right route.

Perhaps you could clarify the question a bit for me though... you have it listed above as you'd like the sort to come out in the end?

I think that would just be something akin to
Code:
$x = ksort($x);

foreach ($x as $key=>$second_level)
{
  $x[$key] = ksort($second_level);
}

No?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top