知道其名称从数组中删除元素

时间:2010-10-29 20:55:51

标签: php arrays

我在PHP中有这个数组

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

我想删除["mai_description"]并仅获取

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

有什么办法吗?

3 个答案:

答案 0 :(得分:4)

是的,请使用unset()

unset( $array['mai_description'] );

答案 1 :(得分:3)

unset($array['mai_description'])

但请使用文档。

答案 2 :(得分:2)

unset($array["mai_description"]);

应该这样做。

/编辑以修复语法错误,即使它与Peter的相同