Re: Trouble with sorting
| From: | (Richard Lynch) | Date: | Sat, 01 Jul 2000 22:11:23 +0000 |
| Subject: | Re: Trouble with sorting | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-4307@lists.php.net to get a copy of this message | ||
In article <39596149.F77A12A7@mail.chita.ru>, ildar@mail.chita.ru (Ildar
Akhmetov) wrote:
> Hello!
>
> I have two text files. One file, named 'players', contains names of
> soccer-players, next file, named 'votes', contains votes for each
> player. Strings numbers are same (#1 in players is #1 in votes, and so
> on).
>
> I need to diaplay a table with player ratings, sorted by rating. How can
> I do this?
This might do it...
<?php
$players = file('/path/to/players') or die('could not find players file.');
$votes = file('/path/to/votes') or die('could not find votes');
rsort($votes);
while (list($index, $votecount) = each($votes)){
echo $players[$index], ": ", $votecount, "<BR>\n";
}
?>
--
Richard Lynch | If this was worth $$$ to you, buy a CD
US Customer Support Director | from one of the artists listed here:
Zend Technologies USA | http://www.L-I-E.com/artists.htm
http://www.zend.com | (this has nothing to do with Zend,
duh!)