What is the best practice for processing multiple dynamically generated form checkboxes in PHP?

When processing multiple dynamically generated form checkboxes in PHP, it is best to use an array for the checkbox inputs in the form. This allows you to easily loop through the array in PHP to handle the selected checkboxes.

// HTML form with dynamically generated checkboxes
<form method="post">
    <input type="checkbox" name="checkboxes[]" value="option1"> Option 1
    <input type="checkbox" name="checkboxes[]" value="option2"> Option 2
    <input type="checkbox" name="checkboxes[]" value="option3"> Option 3
    <input type="submit" name="submit" value="Submit">
</form>

// PHP code to process the selected checkboxes
if(isset($_POST['submit'])) {
    if(!empty($_POST['checkboxes'])) {
        foreach($_POST['checkboxes'] as $selected) {
            echo $selected . " is selected. ";
        }
    } else {
        echo "No checkboxes selected.";
    }
}