[FX.php List] Sorting multidimensional array

Tim 'Webko' Booth tim at nicheit.com.au
Thu Feb 28 16:47:23 MST 2008


On 29/02/2008, at 3:01 AM, Chris Hansen wrote:

> Tim,
>
> What you want is PHP's uasort() function.  So, you could sort  
> something like this:
>
> function CompareDistances ($a, $b)
> {
>    if ($a['Distance'] == $b['Distance']) {
>        return 0;
>    }
>    return ($a['Distance'] < $b['Distance']) ? -1 : 1;
> }
>
> uasort($theDistances, 'CompareDistances');
>
> The function above was modified from one in the PHP documentation  
> (see the usort() entry).  In short, $a and $b will be array  
> elements, and we just need to set up a function which specifies what  
> to sort on.  I so love PHP =)

I so learn something every day ;-)

Dale's answer was pretty much perfect for the current need, but I'll  
have a play with this as well.

Of course, the client now says that the solution is "overengineered"  
and why can't we just search by state but ;-)



More information about the FX.php_List mailing list