2

Possible Duplicate:
PHP: How to remove specific element from an array?

Here in my $_POST, I am quite confused on how to trim or drop the key 'submit'. I'm quite confused with this array manipulation. Thanks.

Array
(
    [Physical_Education] => 43
    [Statistics] => 34
    [Biology] => 43
    [Math] => 34
    [quarter] => 1
    [submit] => Submit Grades
)
Community
  • 1
  • 1
planet x
  • 1,599
  • 5
  • 26
  • 44
  • 3
    Why do you need to remove the key anyways? – NullUserException Dec 09 '11 at 01:32
  • 4
    The `$_POST` array itself isn't really meant to be manipulated. Any information you get from it should be taken out of the array and put into variables or another array; it's better coding practice. – animuson Dec 09 '11 at 01:33
  • What is so weird about unsetting properties in an associative array? JavaScript dedicates a whole keyword to it (`delete`) - ah but yes, `$_POST` is a global thing, don't mess with it too much. – Halcyon Dec 09 '11 at 01:34
  • Thanks for the insights about this. – planet x Dec 09 '11 at 01:34
  • i'm so confused as to why it even includes submit buttons and their values lol – oldboy Sep 12 '17 at 04:07

3 Answers3

14

Using unset() should do the trick:

unset($_POST['submit']);
4

You can unset() the member, like Tim Cooper suggests.

However, if you don't want that being POST'd in the first place, you could drop the name attribute on your submit button.

Community
  • 1
  • 1
alex
  • 479,566
  • 201
  • 878
  • 984
1

Tackle the root of the problem!

It's in there because your submit button looks like this:

<input type="submit" name="submit" value="Submit Grades">

Thus, remove the name and it won't be sent:

<input type="submit" value="Submit Grades">
middus
  • 9,103
  • 1
  • 31
  • 33