View Full Version : Sort array with values starting with numbers
chrisvmarle
05-23-2003, 11:12 AM
I have an array that contains userdata in this form:
"SCORES|USERNAME"
So the array looks like this:
$scoreuser = Array("10|User1","2|User3","5|User2","0|User6");
How can I sort this array by score, starting with the best?
So it should end up like this:
$scoreuser = Array("10|User1","5|User2","2|User3","0|User6");
Thanks in advance
Mzzl, Chris
Weirdan
05-23-2003, 12:00 PM
arsort($scoreuser,SORT_NUMERIC);
chrisvmarle
05-23-2003, 05:23 PM
Thanks, I knew it was that simple, just couldn't figure it out :p
chrisvmarle
05-23-2003, 08:41 PM
Tried it, didn't work:
<?
$fragusers = Array("36","8","26");
arsort($fragusers,SORT_NUMERIC);
for($i=0;$i<sizeof($fragusers);$i++) {
echo "$i: $fragusers[$i]<Br>";
}
?>
Returns:
0: 36|1
1: 8|7
2: 26|6
Not quite right...
Any ideas?
(BTW Array("36","8","26") has te same result
chrisvmarle
05-24-2003, 11:11 AM
Never mind, fixed it
ReadMe.txt
05-24-2003, 10:36 PM
unless you're going to put them into a text file would it not be better to arrange them into a 2D array?
eg
array (array (1,2),array(3,4))
which gives $array[0][0] = 1 and $array[1][1] = 4, give or take a few semi-colons, i always forget where they go in array decs
chrisvmarle
05-24-2003, 11:10 PM
That's what I did:
For all the users:
$fragsusers[$user] = $frags;
then:
arsort ($fragsusers);
Mzzl, Chris
P.S. if think this isn't working, please tell me, because I'm still not sure it does...
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.