I have some troubles with an array. I have one array that I want to modify like below. I want to remove element (elements) of it by index and then re-index array. Is it possible?
$foo = array(
'whatever', // [0]
'foo', // [1]
'bar' // [2]
);
$foo2 = array(
'foo', // [0], before [1]
'bar' // [1], before [2]
);
Try with:
In addition to xzyfer's answer
The function
Use
Result
You better use
array_shift()
. That will return the first element of the array, remove it from the array and re-index the array. All in one efficient method.If you use
array_merge
, this will reindex the keys. The manual states:http://php.net/manual/en/function.array-merge.php
This is where i found the original answer.
http://board.phpbuilder.com/showthread.php?10299961-Reset-index-on-array-after-unset()