Doyley Posted April 3, 2008 Share Posted April 3, 2008 Hi all, I'm having a problem with array keys. Here is my code.. $selectsql="select distinct playerid from results where seasonid='$season'"; $selectnew=mysql_query($selectsql) or die(mysql_error()); while($sel=mysql_fetch_array($selectnew)){ $select2sql="select points from results where playerid='$sel[0]' and seasonid='$season'"; $select2new=mysql_query($select2sql) or die(mysql_error()); while($sel2=mysql_fetch_array($select2new)){ $pl="AA".$sel[0]; $prev=$arr[$pl]; $new=$prev+$sel2[0]; $arr[$pl]=$new; } } rsort($arr); echo "<pre>\n"; print_r($arr); echo "</pre>\n"; The above outputs the following.. Array ( [0] => 50 [1] => 46 [2] => 44 [3] => 34 ) I need it to output Array ( [AA1] => 50 [AA2] => 46 [AA3] => 44 [AA4] => 34 ) If I remove rsort() it works but I need that in there. Can anybody help? Thanks! Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 3, 2008 Share Posted April 3, 2008 rsort resets the index (basically what your seeing) change to arsort should resolve the problem Quote Link to comment Share on other sites More sharing options...
Doyley Posted April 3, 2008 Author Share Posted April 3, 2008 Cheers, I just tried ksort before reading your post and that also worked. Is there a difference between arsort and ksort? Thanks for your help! Quote Link to comment Share on other sites More sharing options...
Doyley Posted April 3, 2008 Author Share Posted April 3, 2008 Nope I was wrong, ksort didn't work. arsort works perfectly. Thanks again! Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 3, 2008 Share Posted April 3, 2008 ksort sorts by keys Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.