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]
);
unset($foo[0]); // remove item at index 0
$foo2 = array_values($foo); // 'reindex' array
This is better than deceze's solution if several items needs to be removed at once - if the indexes of those items are collected beforehand. Once you use array_splice on the first item, you lose the indexes of the rest items.
It may be worth noting that you can unset multiple variables/array indexes in a single unset call
unset($foo[0], $foo[3], $bar[1]);