Jump to content


Photo

Multi-dimensional Array Sort Help Please


  • Please log in to reply
1 reply to this topic

#1 Morri

Morri
  • New Members
  • Pip
  • Newbie
  • 2 posts
  • LocationScotland

Posted 14 September 2006 - 02:07 AM

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

#2 Morri

Morri
  • New Members
  • Pip
  • Newbie
  • 2 posts
  • LocationScotland

Posted 14 September 2006 - 02:24 AM

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.

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');

Anyway back to coding the rest of this thing...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users