Page 1 of 1

Sorting Array Issues

Posted: Wed Oct 18, 2006 10:05 am
by scrypte
Here is how the file looks that I am pulling the information from ->

Code: Select all

staticreality	1	FEAR	59106
blizzard	1	FEAR	59087
P0is0n0us	1	SP00K	58955
emo	1	FEAR	58794
tessa	1	FEAR	58653
baiseur	1	SIMPLY	58340
fkn_jovy	1	MZBRAT	58315
urge_	1	FEAR	58311
arouse	1	SIMPLY	58282
mzbrat	1	MZBRAT	58217
pendulum	1	FEAR	57585
-Mayhem-	1	FEAR	52698
Sp00k	1	SP00K	48017
play_mix	1	FEAR	36916
Thunderous	1	SOLIT	24953
LoveMistress	1	BB16	9258
Mom	1	BB16	4763
Tazzia	1	FEAR	4647
badphish	1	BB16	1778
Xanados	1	SHAFOR	1013
X_kadaj_X	1	SHAFOR	129
Here is the coding I am using

Code: Select all

<?
$array2 = array();
$array2 = file("../../voodoo/users.txt");

foreach ($array2 as $key2 => $value2) {
    list($user,$type,$url,$time ) = explode("\t", $value2);
    $tmp2[$key2]  = $time;
}
array_multisort($tmp2, SORT_DESC, $array2);

	$i = 1;
foreach ($array2 as $key2 => $value2) {
    list($user,$type,$url,$time) = explode("\t", $value2);
    // etc.
    if ($i<6) {
    echo '<tr>';
	echo '<td width=5 class=info bgcolor='.row_color($key2).'>'.$i.'</td>';
	echo '<td width=300 class=info bgcolor='.row_color($key2).'>';
	echo $user.'</td>';
	echo '<td width=20 class=info bgcolor='.row_color($key2).'>'.$time.'</td>';
	echo '</tr>';
    }
	$i++;
}
?>
here is what is printed ->
1 LoveMistress 9258
2 staticreality 59106
3 blizzard 59087
4 P0is0n0us 58955
5 emo 58794

Now my problem is that I need to have it show the highest to lowest and right now because the 1st one is only 4 digits it is not doing that right now.

Can anyone help me figure out why.

Posted: Wed Oct 18, 2006 12:56 pm
by akimm
If I understand correctly, you want to sort the array numerically, as with most things PHP has a preordained function for just that.

PHP.net is your friend.

Code: Select all

SORT_NUMERIC
Another question, you list $array2 variable twice, you give it one value then reassign another. Perhaps you were trying to concatenate the two? if so it would look like this

Code: Select all

###CORRECT
$array2 = array();
$array2 .= file("../../voodoo/users.txt");
####

###INCORRECT
$array2 = array();
$array2 = file("../../voodoo/users.txt");
#####

Posted: Wed Oct 18, 2006 12:58 pm
by akimm
I hope that was helpful. Any other questions?