RE: [PHP] sorting associative array

From: Date: Mon, 24 Jan 2005 12:33:44 +0000
Subject: RE: [PHP] sorting associative array
Groups: php.general 
Request: Send a blank email to php-general+get-207116@lists.php.net to get a copy of this message
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 should be: function cmp($a, $b) > > { > > 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 sort based on the > score key.. Sure it will, given the correction above. Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: m.ford@leedsmet.ac.uk Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211

« previous php.general (#207116) next »