So I’m in the middle of a predicament here. Currently what I’m attempting to do is to delete the index of an array. But at the same time, I’m using the current() and next() functions. So what I have now is this:
[php]$i = 4; // Index of array to delete
unset($array[$i]);
$array = array_unique($array);
while(key(current($array)) != $i) {
next($array);
}[/php]
I’m also aware of the array_splice function, but as far as I know that also destroys the current() data. I’m also a bit confused on how I would use the array_splice() function… from what I gather I, to remove just a single index and keep everything around it, it would be something along the lines of…?
[php]$i = 4; // Index of array to delete
array_splice($array, $i, 1);[/php]
Correct me if I’m wrong on that, and I too believe that the current() value of the array is then reset too. Is there a workaround for this? All I want to do is remove a single index from an array.
Also, is it possible to add an index to an array between two others? For example, I have a list of {“apples”, “grapes”, “oranges”}, but I want to add “cherries” to index 1, so the array is {“apples”, “cherries”, “grapes”, “oranges”}. Is that possible? Thanks!