Arrays
When an item goes deleted the order is restored or it just goes down with 1position? For example if we delete item 2 from an array with 4elems, how it will look like.. 0,1,3? If yes is any solution to be reordered and changed in the normal way? Does anyone knows how array: works here?
|
Re: Arrays
Are we talking about static...
Code:
Code:
|
Re: Arrays
You can't delete values from a static array as such, but you can however recreate something similar to the ArrayDeleteItem() function, and "pull" all of the values down, if you were to assume something like a cell with its value being 0 would be empty.
When you delete an item from a dynamic array, you are actually deleting a cell, therefore all cells that come after the one you deleted will drop 1 position, and the total array size will drop by 1. |
Re: Arrays
It;s about dynamic arrays, when i delete an item and then loop again with the new size i get invalid cellvector errors for the deleted position so i guess that the new array it isn;t remaped.
|
Re: Arrays
Show your code and explain what your trying to do.
|
Re: Arrays
PHP Code:
|
Re: Arrays
Your example doesn't delete the position 2, it deletes whatever position contains the value 2.
If you're going to post an example instead of your actual code, make sure that the example can produce the error. I'm gonna guess that your actual loop doesn't contain break. Because then you will get that error unless you account for the removed entries. Code:
Code:
Code:
PRE: 0: 1 |
Re: Arrays
'==2' was just an value example and not position to delete, the code posted is similar to original that contains ents and i;m checking if those are valid before deletion. Hmm seems like the new array is remaped as it should but why it keeps giving me those errors :stupid:
PHP Code:
|
Re: Arrays
The problem is you delete one cell without recounting or subtract the number of removed indexes.
The code works great except for 2 things. * If you delete one item, the one after will be ignored because it was shifted to the position of the first one. * When the loop reaches the end, it doesn't know that the size has changed. This is the reason it throws an error, you're trying to retrieve values outside of the array range. Look at the example I gave. Especially the variable deleted_items. |
Re: Arrays
Ups i forgot to add a break to the timer condition also, thanks :)
|
| All times are GMT -4. The time now is 19:03. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.