sort multidim array
| From: | Kevin Coyner | Date: | Tue, 05 Oct 2004 17:04:44 +0000 |
| Subject: | sort multidim array | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-198696@lists.php.net to get a copy of this message | ||
I've been banging my head against the wall on this one. Probably
trivial to the knowledgeable, but I'm stumped despite trying the various
sort functions as advertised on php.net.
I've got the following fields:
retailer city state telephone distance
Sample data looks like:
BLIND BROOK CLUB PURCHASE, NY (914) 939-1450 4.6
BURNING TREE CC GREENWICH, CT (203) 869-9010 0
CENTURY COUNTRY CLUB PURCHASE, NY (914) 761-0400 4.6
FAIRVIEW CC GREENWICH, CT (203) 531-4283 2.2
......
All of this is in an array I'll call $zipArray.
When I get the data from mysql, it doesn't contain the 'distance' info.
The distance field is calculated and tacked onto each row by having
everything go through a foreach loop.
So I start with an array that has 4 data columns (retailer, city, state
and telephone) and I end up with an array that has 5 data columns
(retailer, city, state, telephone, and distance).
If I apply asort($zipArray) it sorts nicely on the first data column -
retailer. But I need it to sort on the last data column - distance.
I think I've been staring at this too long. Would appreciate any
guidance.
Thanks
Kevin
--