Re: sorting arrays

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> Say I create a "matches" array from a set of SQL queries With each query,
> an entry is added to my matches array. If the name already exists, its
> value
> gets incremented. How can I sort the array based on the highest number of
> hits?
>
> What is the sort method? Say this is the array:
>
> array('lma-bg51' => 1, 'mcr-vh14' => 2, 'gmc-rr21' => 5, 'amh-fg23' => 1)

Seems like some folks gave this guy a hard time, and he didn't deserve it.

Any newbie could RTFM and not "get" that when you see:
bool arsort ( array &array [, int sort_flags] )

the "bool" up front tells you that the function returns a boolean
(true/false) value.

That should in the future be an important fact to note.

Another thing to watch for is the & in the docs.

That generally means that the function is going to *CHANGE* the value you
pass in, in some way, and you can't rely on it being the same as what you
handed off to the function.

In the case of arsort, that's exactly what you want, of course.

In other cases, it might mean that you need to only give the function a
*COPY* of the data, so you can keep your copy safe and un-altered.

These are all consistent usage throughout the manual, so you might as well
get used to them.

More info about this is buried here:
http://us4.php.net/manual/en/about.prototypes.php

in Appendix Q, way the hell at the end of the manual...

Hmmmm.  Guess you can't have everything at the beginning of the manual,
but a reference to the reference buried at the end?... [shrug]



-- 
Like Music?
http://l-i-e.com/artists.htm

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux