PHP Multiple Checkbox Array
Creating a form with multiple checkboxes and capturing user selections into an array in PHP can be straightforward. Here's how you can implement it:
<form method='post'>
Now, in your PHP script:
<?php if (isset($_POST['checkboxvar'])) { print_r($_POST['checkboxvar']); } ?>
By passing the name attribute of your checkbox inputs as an array (checkboxvar[]), all checked values will be automatically captured within the $_POST['checkboxvar'] array. You can then echo or manipulate these values as needed.
To send the checked values in an email, you can implode the array into a string, separating the values with a comma or any other separator:
echo implode(',', $_POST['checkboxvar']); // change the comma to your desired separator
Remember to sanitize your input before using it in your email to prevent any malicious code from being executed. For more information on this topic, you can refer to the official PHP documentation here: http://php.net/manual/en/faq.html.php#faq.html.arrays
The above is the detailed content of How to Capture Multiple Checkbox Selections as an Array in PHP?. For more information, please follow other related articles on the PHP Chinese website!