Re: [PHP] sorting associative array

2005-01-24 Thread Jeffery Fernandez
Jochem Maas wrote: Jeffery Fernandez wrote: Jochem Maas wrote: ... Yes the example sent by Kurt Yoder worked for me. I coudn't work out the errors with the class you sent me. I realised it was written for PHP5 in mind ?... or maybe I wasn't patient enough to spent time debugging it :-( I d

Re: [PHP] sorting associative array

2005-01-24 Thread Jochem Maas
Jeffery Fernandez wrote: Jochem Maas wrote: ... Yes the example sent by Kurt Yoder worked for me. I coudn't work out the errors with the class you sent me. I realised it was written for PHP5 in mind ?... or maybe I wasn't patient enough to spent time debugging it :-( I did change it for php

RE: [PHP] sorting associative array

2005-01-24 Thread Ford, Mike
To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm On 23 January 2005 22:37, Jeffery Fernandez wrote: > Kurt Yoder wrote: > > > Use usort (stealing from php docs): > > > > > > > > function cmp($a['score'], $b['score']) That sho

Re: [PHP] sorting associative array

2005-01-24 Thread Jeffery Fernandez
Jochem Maas wrote: ... This won't work for me as I have 500+ records to sort based on the score key.. looking at jochem's class now. Thanks which wont help much - assuming what you say is true (why wont it work? have you tried it). sort method from the class: function sort() { if

Re: [PHP] sorting associative array

2005-01-24 Thread Jochem Maas
... This won't work for me as I have 500+ records to sort based on the score key.. looking at jochem's class now. Thanks which wont help much - assuming what you say is true (why wont it work? have you tried it). sort method from the class: function sort() { if(count($this->sortKe

Re: [PHP] sorting associative array

2005-01-24 Thread Abdul-Wahid Paterson
Hi, How about this foreach ($data as $key => $row) { $scores[$key] = $row['scores']; } array_multisort($scores, SORT_ASC, $data); Abdul-Wahid On Mon, 24 Jan 2005 00:39:17 +1100, Jeffery Fernandez <[EMAIL PROTECTED]> wrote: > I have the following multi-dimentional

Re: [PHP] sorting associative array

2005-01-23 Thread Jeffery Fernandez
Jochem Maas wrote: Jeffery Fernandez wrote: Kurt Yoder wrote: Use usort (stealing from php docs): function cmp($a['score'], $b['score']) { if ($a['score'] == $b['score']) { return 0; } return ($a['score'] < $b['score']) ? -1 : 1; } $data = array(...); usort($data, "cmp"); This won

Re: [PHP] sorting associative array

2005-01-23 Thread Jochem Maas
Jeffery Fernandez wrote: Kurt Yoder wrote: Use usort (stealing from php docs): function cmp($a['score'], $b['score']) { if ($a['score'] == $b['score']) { return 0; } return ($a['score'] < $b['score']) ? -1 : 1; } $data = array(...); usort($data, "cmp"); This won't work for me as I

Re: [PHP] sorting associative array

2005-01-23 Thread Jeffery Fernandez
Kurt Yoder wrote: Use usort (stealing from php docs): function cmp($a['score'], $b['score']) { if ($a['score'] == $b['score']) { return 0; } return ($a['score'] < $b['score']) ? -1 : 1; } $data = array(...); usort($data, "cmp"); This won't work for me as I have 500+ records to sor

Re: [PHP] sorting associative array

2005-01-23 Thread Kurt Yoder
Use usort (stealing from php docs): function cmp($a['score'], $b['score']) { if ($a['score'] == $b['score']) { return 0; } return ($a['score'] < $b['score']) ? -1 : 1; } $data = array(...); usort($data, "cmp"); On Jan 23, 2005, at 8:39 AM, Jeffery Fernandez wrote: I have the follo

Re: [PHP] sorting associative array

2005-01-23 Thread Jochem Maas
Jeffery Fernandez wrote: I have the following multi-dimentional array and I want to sort it by the "score" key value ... any ideas. Thanks A long time ago I had this problem, came up with the following class (based on someone else's stuff that I found in the comments section of the php manual) to