Huijari Posted June 14, 2010 Share Posted June 14, 2010 So I have a code: //Example there are 2 levels with same number of plays (3 plays) $array[$plays] = $level; // at the end of code krsort($array,SORT_NUMERIC); If it now takes level with 3 plays, it adds it to array but when next level with same plays comes, it comes in array as it. My code is to sort these levels so that level with most plays is first. Here's what I mean: $array[3] = level1; // next time $array[3] = level2; I tried this: if ($array[$plays]=="") { $array[$plays] = $level; } else { $array[$plays+1] = $level; } But it won't work because if you have 3 levels with plays 3,3 and 4, and level with 4 plays comes first to array Then when comes 3, its ok But then the next 3, it adds 1 to it, so its 4, but there is already array[4] so it won't work Quote Link to comment https://forums.phpfreaks.com/topic/204781-arrays-array1-gets-overwrote-by-next/ Share on other sites More sharing options...
F1Fan Posted June 14, 2010 Share Posted June 14, 2010 What's wrong with this? $array[] = $level; Quote Link to comment https://forums.phpfreaks.com/topic/204781-arrays-array1-gets-overwrote-by-next/#findComment-1072110 Share on other sites More sharing options...
Huijari Posted June 14, 2010 Author Share Posted June 14, 2010 That code is supposed to sort all the levels by number of $plays thats why cant use that Quote Link to comment https://forums.phpfreaks.com/topic/204781-arrays-array1-gets-overwrote-by-next/#findComment-1072112 Share on other sites More sharing options...
F1Fan Posted June 14, 2010 Share Posted June 14, 2010 Then I don't understand what you're trying to do. Could you explain a little more? Show you're existing code then what the unwanted results are. Don't display any code that you're not already using. Quote Link to comment https://forums.phpfreaks.com/topic/204781-arrays-array1-gets-overwrote-by-next/#findComment-1072113 Share on other sites More sharing options...
Huijari Posted June 15, 2010 Author Share Posted June 15, 2010 nevermind, go it fixed with using instead of this $array[$plays] = $level; this $array[$level] = $plays; Quote Link to comment https://forums.phpfreaks.com/topic/204781-arrays-array1-gets-overwrote-by-next/#findComment-1072285 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.