note 21974 deleted from function.sort by derick

From: Date: Wed, 31 Aug 2005 10:38:52 +0000
Subject: note 21974 deleted from function.sort by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-94498@lists.php.net to get a copy of this message
Note Submitter: matthew at sagacity dot com dot au ---- I needed to sort a multi-dimensional football results array by two columns; first by competition points then by for/against. As they were both numerical values I was able to simply add the competition points to the for/against divided by 100. e.g. Points Goals Team 1: 0 -1 Team 3: +3.02 Team 2: 3 +1 became Team 2: +3.01 Team 3: 3 +2 (once sorted) Team 1: -0.01 Team 4: 0 -2 Team 4: -0.02 If your second column is likely to contain larger numbers, divide by a higher power of 10. Otherwise a team with 10 competion points and 51 goals against [10 + (-51 / 100) = 9.49] would sort below a team with 9 competition points and 51 goals for [9 + (51 / 100) = 9.51]). Dividing by 1000 in this case would give you 9.949 and 9.051 (which would sort correctly). Hope I made that clear!

« previous php.notes (#94498) next »