Re: Trouble with sorting

From: Date: Tue, 27 Jun 2000 14:51:20 +0000
Subject: Re: Trouble with sorting
Groups: php.general 
Request: Send a blank email to php-general+get-3344@lists.php.net to get a copy of this message
Ildar, Try this: <?php $players=file("players"); $votes=file("votes"); for($i=0;$i<count($players);$i++) { $sortArray[]=array("name"=>$players[$i],"votes"=>$votes[$i]); } function compare($a,$b) { if ($a["votes"]==$b["votes"]) return 0; return ($a["votes"] > $b["votes"]) ? -1 : 1; // sort ascending } usort($sortArray,"compare"); for($i=0;$i<count($sortArray);$i++) { $line=$sortArray[$i]; echo "Player=${line["name"]} Votes=${line["votes"]}<BR>"; } ?> Regards, Carroll Barrett -----Original Message----- From: Ildar Akhmetov <ildar@mail.chita.ru> To: php-general@lists.php.net <php-general@lists.php.net> Date: Tuesday, June 27, 2000 2:40 AM Subject: [PHP-GENERAL] Trouble with sorting >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? > >Thank you, Ildar. > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net >For additional commands, e-mail: php-general-help@lists.php.net >To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#3344) next »