Reputation: 11
Okay, so I learned that if I have a form like:
<form method="post" action="arrayplay2.php">
<input type="checkbox" value="1" name="todelete[]"/>
<input type="checkbox" value="2" name="todelete[]"/>
<input type="checkbox" value="3" name="todelete[]"/>
<input type="checkbox" value="4" name="todelete[]"/>
<input type="submit" value="delete" name="delete"/>
</form>
that the attribute name="todelete[]" initiates an array. How? And then how do I access this and the values in each one with the $_POST superglobal on my arrayplay2.php script?
Upvotes: 1
Views: 244
Reputation: 4124
With form like that you get indeed an array in $_POST superglobal named todelete. Array will be numeric array starting with index 0.
You can loop that array:
foreach($_POST['todelete'] as $val){
echo $val;
}
Or you can directly access desired index:
echo $_POST['todelete'][2];
Upvotes: 2