View Single Post
Old 03-03-2013, 01:55 AM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
If you need to keep it sequential and compact in the array, and sized only large enough to hold the items within it, then you'd be better of with a second array. Simply iterate through the array that exists, and push onto the new array. If you hit the matching item to remove, then skip it, and keep going. If the end result is that no item was removed, than return the original, otherwise return the new.
This said, if you keep only an array large enough to hold a given number of items at the time, than its not really optimized. It's quite a bit of effort to copy an array into a larger one, than it is to leave unused space.
Compare it to the add. The remove should be pretty much the exact opposite. If you create an array of current.length + 1, then add an item to it, then it makes sense to do the same with remove. If the add is not always incrementing the current array and creating a new one, than I'd suggest that the remove should not and instead simply setting the offset when found to null.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote