array_splice()
If you use array_splice()
the keys will be automatically reindexed, but the associative keys won’t change opposed to array_values()
which will convert all keys to numerical keys.
Also array_splice()
needs the offset, not the key!, as second parameter.
Code
php
$array = array(0 => "a", 1 => "b", 2 => "c");
array_splice($array, 1, 1);
//↑ Offset which you want to delete
?>
Output
Array (
[0] => a
[1] => c
)
array_splice()
same as unset()
take the array by reference, this means you don’t want to assign the return values of those functions back to the array.