...

View Full Version : Sorting a Multi-Dimensional Array



drscares
11-03-2007, 06:14 PM
Hi Everyone.

I have an array that prints like this:
Array (
[dist] => Array (
[0] => 1.0
[1] => 0.2
[2] => 0.9
[3] => 1.0
)
[loc] => Array (
[0] => Dean Playground Park
[1] => Eckhart Park
[2] => Pulaski Park
[3] => Skinner Park
)
)

I would like to sort this array by DIST but have the keys match up, IE

Array (
[dist] => Array (
[0] => 0.2
[1] => 0.9
[2] => 1.0
[3] => 1.0
)
[loc] => Array (
[0] => Eckhart Park
[1] => Pulaski Park
[2] => Dean Playground Park
[3] => Skinner Park
)
)

Is this possible? How would I go about this?

Thanks in advance!!

Mwnciau
11-03-2007, 07:13 PM
array_multisort($array['dist'], $array['loc']);

drscares
11-04-2007, 04:37 PM
Mwnciau you saucy Minx! I knew their had to be some function for this. You are my hero.

For anyone referencing this thread, Mwnciau's solution solved the problem and output the array exactly as I needed it.

For more uses of this refer here:
http://us.php.net/array_multisort

Thanks again Mwnciau!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum