I have an array that can contain numeric or associative keys, or both:
$x = array('a', 'b', 'c', 'foo' => 'bar', 'd', 'e'); print_r($x);
I want to be able to remove an element from an array, renumber non-associative keys to save them in sequence:
$x = remove($x, "c"); print_r($x);
Finding the right item to delete is not a problem; these are the keys that are the problem. unset does not renumber the keys, and array_splice works with an offset rather than a key (i.e., take $ x from the first example, array_splice($x, 3, 1) will remove the bar element, not the d element) .
arrays php associative-array
nickf
source share