Jump to content

Multi-dimensional Array Sort Help Please


Morri

Recommended Posts

I have a multi-dimensional array in the following format:

Array
(
    [key1] => Array
        (
            [subkey1] => name1
            [subkey2] => ...
            [subkey3] => ...
            [subkey4] => ...
            [subkey5] => ...
            [subkey6] => ...
            [subkey7] => ...
        )

    [key2] => Array
        (
            [subkey1] => name2
            [subkey2] => ...
            [subkey3] => ...
            [subkey4] => ...
            [subkey5] => ...
            [subkey6] => ...
            [subkey7] => ...
        )

Is there anyway i can sort the array by a subkey value (name# for instance)?

I'd be greatful for any help.

Thanks,
        John
Link to comment
Share on other sites

I really should browse the net a bit before i post... ::) :-[

More or less found the answer then i modified it to get the code below.

[code]function compare($x, $y)
{
if ( $x[subkey1] == $y[subkey1] )
  return 0;
else if ( $x[subkey1] < $y[subkey1] )
  return -1;
else
  return 1;
}

uasort($fonts, 'compare');[/code]

Anyway back to coding the rest of this thing...
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.