Jump to content

Arrays array[1] gets overwrote by next


Huijari

Recommended Posts

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.