Jump to content

Archived

This topic is now archived and is closed to further replies.

Morri

Multi-dimensional Array Sort Help Please

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

Share this post


Link to post
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...

Share this post


Link to post
Share on other sites

×

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.