Processing HTML checkboxs with same names as an associative array in PHP

Here’s the HTML form:

<form action="test-html-form-process.php" method="post">
    me <input type="checkbox" name="test[me]" value="me">
    him <input type="checkbox" name="test[him]" value="him">
    <hr>
    <button type="submit">Send</button>
</form>

and then in the PHP side, I can loop through $_POST['test'] and access all the checked values, however, either of these gives an error:

var_dump($_POST['test']['me']); //I checked `me` box in the HTML form. //error: Notice: Undefined index: me in...
var_dump($_POST['test']['him']); //I checked `him` box in the HTML form. //error: Notice: Undefined index: him in...

Could you please explain this to me. Thanks a ton.

Have a look at the complete array: var_dump($_POST);

1 Like

Maybe this will help clear things up a bit?

http://php.net/manual/en/faq.html.php#faq.html.arrays

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.