I am having problems sorting a multi-dimensional array. I am hoping that somebody can help me figure out what I am doing wrong. It should sort on the "field" than on the "fac". Here is my code:
-----start code-----

function cmp ($a, $b) {
GLOBAL $sortterm;
    return strcmp($a[$sortterm], $b[$sortterm]);

function get_locations(){
GLOBAL $sortterm;

usort($locs, "cmp");
usort($locs, "cmp");
while (list ($key, $value) = each ($locs)) {
echo $locs[$key][loc_id].", ".$locs[$key][fac].", ".$locs[$key][field]."<br>\n";
-----end code-----

Here is how it comes out when run:
12, Johnson County Community College, C
11, Johnson County Community College, B
13, Johnson County Community College, D
14, Johnson County Community College, E
10, Johnson County Community College, A
8, Johnson County Girls Athletic Assoc, D
6, Johnson County Girls Athletic Assoc, B
7, Johnson County Girls Athletic Assoc, C
5, Johnson County Girls Athletic Assoc, A
9, Shawnee Civic Center, 1
1, Tomahawk Sports Dome, 1
2, Tomahawk Sports Dome, 2
3, Tomahawk Sports Dome, 3
4, Tomahawk Sports Dome, 4

As you can see, the fac is sorted correctly, but the field isn't.


This message has been scanned for viruses and
dangerous content by the MailScanner at ow5, and is
believed to be clean.

-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to