开发者

Removing an element from the array knowing its name

开发者 https://www.devze.com 2023-01-22 20:57 出处:网络
I have this array in PHP array(5) { [\"mai_id\"] => string(1) \"3开发者_如何学运维\" [\"mai_logo\"] => string(0) \"\"

I have this array in PHP

array(5) {
  ["mai_id"] => string(1) "3开发者_如何学运维"
  ["mai_logo"] => string(0) ""
  ["mai_title"] => string(16) "Vitrine Cultural"
  ["mai_description"] => NULL
  ["mai_description2"] => NULL
}

And I'd like to remove ["mai_description"] and get only

array(5) {
  ["mai_id"] => string(1) "3"
  ["mai_logo"] => string(0) ""
  ["mai_title"] => string(16) "Vitrine Cultural"
  ["mai_description2"] => NULL
}

is there any way?


Yup, use unset()

unset( $array['mai_description'] );


unset($array['mai_description'])

but use documentation, please.


unset($array["mai_description"]);

ought to do the trick.

/ edited to fix syntax error even though it's the same as Peter's

0

精彩评论

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

关注公众号