Jump to content

Remove from associative array


The Little Guy

Recommended Posts

I have an array that could look simular to this:

playersArr = Array(1 => 'cat', 3 => 'fish', 9 => 'bird', 5 => 'mouse');
function removePlayer(id){
playersArr.splice(id,1);
}

 

Then there is a function, that is supposed to remove an element from the array (removePlayer).

 

I then have a button next to each one to remove it from the array. So if you want to remove one you press the button and it fires up removePlayer() and removes that id from the array.

 

The problem is that if I remove from the array 1, 3, 9, 5 in that order (one at a time) it will remove all but #5.

But...

If I remove from the array 5, 9, 3, 1 in that order (one at a time) it will remove them all.

 

does that make any sense???

Link to comment
https://forums.phpfreaks.com/topic/94920-remove-from-associative-array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.