简体   繁体   中英

How to unset a key on a $_POST array?

I have some code to intercept a POST request, and then based on the value of another key, to unset a different key. However that part isn't working.

I know this is not the ideal method of doing this, but the script is an add-on to an existing open source platform, so I'm unable to modify existing scripts.

if($_POST['id']['txt_10'] == "Initials"){
    unset($_POST['id']['id[8]']);
}else if($_POST['id']['txt_10'] == "Name"){
    unset($_POST['id']['id[1]']);   
}

However this code doesn't do anything and doesn't even display an error. Using a var_dump($_POST['id']); I can see the key is still set.

--

This is the var_dump of the $_POST['id'] array:

array(7) {
    ["txt_10"]=> string(4) "Name" 
    ["txt_11"]=> string(0) "" 
    [1]=> int(72) 
    [4]=> int(0) 
    [8]=> int(170) 
    ["txt_7"]=> string(7) "wefgweg" 
    [5]=> int(0) 
}

unset($_POST['id'][8])将是正确的解决方法

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM