The following "Seems" to work. But does anybody know how reliable this might be? Baically, I have a multi-dimensional array and want to sort by one column first, than another than another. Right now, I am using a temporary table in MySQL, but want to speed things up if possible. The command there would be to "ORDER BY column1,column3,column2" in my select statement. If I kept it in a multi-dimensional array, would the following be "reliable"
1,b,a
2,a,c
1,e,b

function dostuff(){
usort($array, "column1");
usort($array, "column3");
usort($array, "column2");
// I would be doing any of my outputting here after the sorting.
}

function column1 ($a, $b) {
return strcmp($a["column1name"], $b["column1name"]);
}

function column2 ($a, $b) {
return strcmp($a["column2name"], $b["column2name"]);
}

function column3 ($a, $b) {
return strcmp($a["column3name"], $b["column3name"]);
}

output should be
1,b,a
1,e,b
2,a,c

Yes, this is only 3 rows in this array, but the live one would have hundreds or thousands in it. I do hope that you experts understand what I am trying to do here.
The above problem is why I was wondering also if I could have the function collect one more variable so that I could call it with the column name that I want to sort by. So that I don't have to have 3 different functions to do the job. Anybody know who I could go about doing that?


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

Reply via email to