How do you sort a 2-dimensional array? I'm stumped!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Phil Powell

    How do you sort a 2-dimensional array? I'm stumped!

    $fbArray[$j] = array($feedback CategoryArray[$i]['attributes']['NAME'] =>
    $feedbackCatego ryArray[$i]['attributes']['DISPLAYNAME']);

    I can't begin to fathom in my befuddled mind how to sort this array $fbArray
    into alphabetical order according to
    $feedbackCatego ryArray[$i]['attributes']['NAME'] - I am utterly lost, can
    someone explain in detail how I would do it and why.

    Thanx
    Phil


  • Phil Powell

    #2
    Re: How do you sort a 2-dimensional array? I'm stumped!

    Sorry that didn't work for me, not entirely. Although thanx for the ksort
    suggestion, that was on the way!

    This apparently works (after 3am frustration and trial-and-error):

    function strrevcasecmp($ a, $b) {
    if (strcasecmp($a, $b) == 0) return 0;
    return (strcasecmp($a, $b) > 0) ? -1 : 1;
    }

    @ksort($fbArray );
    if (sizeof($fbArra y) > 0) {
    foreach ($fbArray as $key => $val) {
    @uksort($val, "strrevcasecmp" );
    $fbArray[$key] = $val;
    }
    }

    Phil

    "David" <fingolfin@btin ternet.com> wrote in message
    news:bh28m7$cjc $1@sparta.btint ernet.com...[color=blue]
    > wouldnt that just be
    >
    > ksort($fbArray)
    >
    >
    > "Phil Powell" <soazine@erols. com> wrote in message[/color]
    news:ZW0Za.1106 8$cf.5318@laker ead04...[color=blue][color=green]
    > > $fbArray[$j] = array($feedback CategoryArray[$i]['attributes']['NAME'] =>
    > > $feedbackCatego ryArray[$i]['attributes']['DISPLAYNAME']);
    > >
    > > I can't begin to fathom in my befuddled mind how to sort this array[/color][/color]
    $fbArray[color=blue][color=green]
    > > into alphabetical order according to
    > > $feedbackCatego ryArray[$i]['attributes']['NAME'] - I am utterly lost,[/color][/color]
    can[color=blue][color=green]
    > > someone explain in detail how I would do it and why.
    > >
    > > Thanx
    > > Phil
    > >
    > >[/color]
    >
    >[/color]


    Comment

    • matty

      #3
      Re: How do you sort a 2-dimensional array? I'm stumped!

      Phil Powell wrote:
      [color=blue]
      > Sorry that didn't work for me, not entirely. Although thanx for the ksort
      > suggestion, that was on the way!
      >[/color]

      OK, I'm guessing that you haven't seen the info on array user sort
      functions in the PHP manual at


      Maybe your internet connection blocks you from accessing php.net, or
      any mirrors, or from downloading a copy of the PHP manual from anywhere
      else.

      Try reading it - you'd be amazed at the information there!

      Comment

      Working...