1

I have this $array in which the index key could appear in any random order:

array(4) {
  ["foo"]=> bool(false)
  ["index"]=> bool(false)
  ["bar"]=> bool(true)
  ["biff"]=> bool(false)
}

Without adjusting the position of the elements or changing the key or value, how do I remove the index element, resulting in a new $array?

array(3) {
  ["foo"]=> bool(false)
  ["bar"]=> bool(true)
  ["biff"]=> bool(false)
}

3 Answers 3

6

Use:

unset($array['index']);
Sign up to request clarification or add additional context in comments.

1 Comment

Ya know, I'm too tired to be working right now. Thanks, folks. =)
4
unset($array['index']);

Comments

3

unset($array['index']); is what you're looking for. This will work even if there is no 'index' key in the array.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.