If you give the checkboxes the same name, ending in [], the values are returned as an array.
1 2 |
<input type="checkbox" name="fruit[]" value="apple" /> <input type="checkbox" name="fruit[]" value="grapefruit" /> |
Then in PHP …
1 2 3 4 5 6 |
if( isset($_POST['fruit']) && is_array($_POST['fruit']) ) { foreach($_POST['fruit'] as $fruit) { echo "I have a {$fruit}!"; } $fruitList = implode(', ', $_POST['fruit']); } |
Read more