473,385 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

$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
2 11748
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Thomas Philips | last post by:
I recently had the need to sort a large number of lists of lists, and wondered if an improvement to the Decorate-Sort-Undecorate idiom is in the works. Ideally, I would like to sort the list of...
1
by: Kamilche | last post by:
I've written a generic sort routine that will sort dictionaries, lists, or tuples, either by a specified key or by value. Comments welcome! import types def sort(container, key = None,...
20
by: Xah Lee | last post by:
Sort a List Xah Lee, 200510 In this page, we show how to sort a list in Python & Perl and also discuss some math of sort. To sort a list in Python, use the “sort” method. For example: ...
0
by: Mainlander | last post by:
I have a class that I designed that contains some objects in its fields, that are derived from the TList class. I want to use the TList Sort procedure to sort the items that are in the derived...
7
by: DC Gringo | last post by:
I have a datagrid that won't sort. The event handler is firing and return label text, just not the sort. Here's my Sub Page_Load and Sub DataGrid1_SortCommand: -------------------- Private...
99
by: Shi Mu | last post by:
Got confused by the following code: >>> a >>> b >>> c {1: , ], 2: ]} >>> c.append(b.sort()) >>> c {1: , ], 2: , None]}
10
by: Jim Andersen | last post by:
I have this xml-file. I want to sort it, and create a new xml-file. The result should be identical to the input except that it's sorted. <?xml version="1.0" encoding="UTF-8"?> <levelone> <child...
0
by: Raj | last post by:
We are on a db2 v8.2 (fix 8) with DPF & intra parllelism. Below are sort related configuration settings ...
10
by: Woody Ling | last post by:
In 32 bits DB2 environment, is it meaningful to set sheapthres larger than 256MB for the following case.. 1. Intra-parallel is ON 2. Intra-parallel is OFF
5
by: neehakale | last post by:
I know that heap sort,quick sort and merg sort are the faster sorting algoritms than the bubble sort,selection sort,shell sort and selection sort. I got an idea,in which situation we can use...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.