By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,751 Members | 1,216 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,751 IT Pros & Developers. It's quick & easy.

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

P: n/a
$fbArray[$j] = array($feedbackCategoryArray[$i]['attributes']['NAME'] =>
$feedbackCategoryArray[$i]['attributes']['DISPLAYNAME']);

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

Thanx
Phil
Jul 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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($fbArray) > 0) {
foreach ($fbArray as $key => $val) {
@uksort($val, "strrevcasecmp");
$fbArray[$key] = $val;
}
}

Phil

"David" <fi*******@btinternet.com> wrote in message
news:bh**********@sparta.btinternet.com...
wouldnt that just be

ksort($fbArray)
"Phil Powell" <so*****@erols.com> wrote in message

news:ZW0Za.11068$cf.5318@lakeread04...
$fbArray[$j] = array($feedbackCategoryArray[$i]['attributes']['NAME'] =>
$feedbackCategoryArray[$i]['attributes']['DISPLAYNAME']);

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

Thanx
Phil


Jul 16 '05 #2

P: n/a
Phil Powell wrote:
Sorry that didn't work for me, not entirely. Although thanx for the ksort
suggestion, that was on the way!


OK, I'm guessing that you haven't seen the info on array user sort
functions in the PHP manual at
http://www.php.net/manual/en/ref.array.php

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!
Jul 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.