开发者

How to remove an element from a PHP array if the key equals 'index'?

开发者 https://www.devze.com 2022-12-15 15:30 出处:网络
I have this $array in which the index key could appear in any random order: array(4) { [\"foo\"]=> bool(false)

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 ele开发者_如何学Cment, resulting in a new $array?

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


Use:

unset($array['index']);


unset($array['index']);


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

0

精彩评论

暂无评论...
验证码 换一张
取 消