Firstly, YES, this is a duplicate issue that's been asked 100 times on here, and I've read through many of the posts, but the examples given aren't working 100% for me and I can't figure out where I'm going wrong.
I want to sort an array like this by the 'distance' key, and I want the sort to be "expanded" across the entire array so it reorders all keys in the array. In essence, just like you'd get if you sorted a column in a spreadsheet and expanded the sort across all columns.
Here's the sample array:
$locations = array (
[phone] => Array (
[0] => 555-123-1234
[1] => 555-456-4321
[2] => 555-789-1122
[3] => 555-321-1111 )
[address] => Array (
[0] => 123 Main Street BigCity, NY 12345
[1] => 456 Maple Street Somewhere, UT 87654
[2] => 999 1st Ave MyTown, VA 23456
[3] => 321 2nd Ave MyTown, VA 23456 )
[distance] => Array (
[0] => 24.56
[1] => 13.05
[2] => 23.99
[3] => 1.75 )
[name] => Array (
[0] => First Location
[1] => Second Location
[2] => Third Location
[3] => Fourth Location )
)
I'm trying to sort the array by 'distance', and I've tried using both the array_multisort() function and the usort() function ...but only "multisort" gives me nearly usable results by sorting the distances only and not sorting the entire array according to distance.
My function:
array_multisort($locations['distance'], SORT_NUMERIC);
I then run a "for" loop to traverse the array and spit out the values by key. The result is the distances are ordered but the Location names, addresses, etc. don't get reordered.
What am I missing here??
Thanks!!