Checkboxes that share a name ending in [] arrive in PHP as an array. Treat the field as optional because no value is submitted when none of the boxes are selected.
$selected = $_POST['box'] ?? [];
if (!is_array($selected)) {
$selected = [];
}
foreach ($selected as $value) {
echo htmlspecialchars($value, ENT_QUOTES, 'UTF-8') . '
';
}Validate expected values on the server before using submitted checkbox values in a database or another sensitive operation.
| smo1234 | 18-06-2012 |
| Good one thanks | |