Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Sorting a Multi-Dimensional Array

    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!!

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    PHP Code:
    array_multisort($array['dist'], $array['loc']); 

  • Users who have thanked Mwnciau for this post:

    drscares (11-04-2007)

  • #3
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •