|
Posted by Ivαn Sαnchez Ortega on 01/01/08 02:38
mantrid wrote:
> I am particularly puzzled by what the function [...]
> is doing exactly. Particularly where argument $b comes from, and how it
> and the returned values -1,0 and 1 are affecting the ordering of the
> array.
[...]
> If anyone wants to explain this to me in simple english I'd be grateful.
> If not, no worries Im just glad it works. Been on this for 4 days now.
I could explain, but I'm growing a bit worn out by this loooong thread. And
I'd give you a headache too :-P
So: grab the nearest book on algorithmics, and open it up on the chapter
about sorting algorithms. Every sort algorithm depends on a comparison
function, to know if a item on the soon-to-be-sorted-out-list is "bigger"
or "smaller" than other item.
Really, do grab a book on algorithmics.
BTW, my solution was along the lines of *not* touching the array indexes and
declaring the comparison function something like this:
function usort_cmp($a, $b)
{
return ($a['date'] > $b['date'])
}
Reason behind this: you're comparing arrays (a set of id, date, companyid,
price, etc etc). One of those arrays is bigger than the other if the date
of the first array is bigger than the date of the second array.
Got the idea?
> Ever heard the one where you give a group of monkeys pens and paper and
> given enough time they will write the complete works of shakespere.
No, you're wrong. It's "old typewriters" ;-)
http://en.wikipedia.org/wiki/Infinite_monkey_theorem
--
----------------------------------
IvΓ‘n SΓ‘nchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-
Proudly running Debian Linux with 2.6.22-3-amd64 kernel, KDE 3.5.8, and PHP
5.2.4-2 generating this signature.
Uptime: 03:28:40 up 39 days, 13:44, 4 users, load average: 0.53, 0.79,
0.77
[Back to original message]
|