note 21974 added to function.sort
| From: | matthew@php.net | Date: | Sun, 02 Jun 2002 16:31:37 +0000 |
| Subject: | note 21974 added to function.sort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-31344@lists.php.net to get a copy of this message | ||
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!
--
http://www.php.net/manual/en/function.sort.php
http://master.php.net/manage/user-notes.php?action=edit+21974
http://master.php.net/manage/user-notes.php?action=delete+21974
http://master.php.net/manage/user-notes.php?action=reject+21974