Trying the method that WeedPacket pointed out to me I'm still getting unfavorable results... more help please!
I changed the array structure to: $location[$i][$assoc]
$listing[$i] = array(
'school' => $school[$i],
'city' => $city[$i],
'state' => $state[$i],
'students' => $students[$i],
'contacts' => $contacts[$i],
'budget' => $budget[$i],
'school_year' => $school_year[$i],
'id' => $id[$i])
Then I wrote this function:
function natorder($key, $a, $b) {
return strnatcmp ( $a[$key], $b[$key] );
}
Then called
uasort($listing, natorder($order_by));
Where $order_by is the name of an associative $key.
After calling print_r($listing) It gets sorted, but it's weird...
I expected it reordered this way:
Array(
[0][school] => str
[0][students] => int
...
[1][school] => str
[1][students] => int
...
[2][school] => str
[2][students] => int
...)
But I get instead (when sorted by 'budget'):
Array (
[2] => Array (
[school] => Georgetown University
[students] => 27500
...)
[1] => Array (
[school] => University of Marconia
[students] => 32000
....)
[0] => Array (
[school] => University of Legal Services
[students] => 28575
....)
)
From PHP.net it says that uasort will reorder the multidemnsional array so that "array indices maintain their correlation"... and that it does, but it's more than the correlation, it actually maintains the index as well, instead of reordering into the new "[0][],[1][],[2][]" structure it just switches around the indexes so that print_r will show "[2][],[0][],[1][]" or "[2][],[1][],[0][]"... or whatever it orders it into... that does me no good...
Furthermore it only seems to work when I explicitly name the key value in natorder($key, $a, $b)... because when I pass $key to the function as a variable it always orders it in the "[2][],[1][],[0][]" structure no matter what.
What am I doing wrong???
I looked at a couple of examples at PHP.net, uasort() , but I didn't really understand them and couldn't get them to work with my natorder() function... which I'm not even sure I'm using right?
😕