What are the potential pitfalls of grouping data from checkboxes in PHP forms without clear identifiers?

When grouping data from checkboxes in PHP forms without clear identifiers, it can be challenging to differentiate between the selected checkboxes and their corresponding values. To solve this issue, you can assign unique identifiers to each checkbox element using the 'name' attribute. This way, you can easily access the selected checkboxes in the PHP script by their identifiers.

<form method="post">
    <input type="checkbox" name="fruits[]" value="apple"> Apple
    <input type="checkbox" name="fruits[]" value="banana"> Banana
    <input type="checkbox" name="fruits[]" value="orange"> Orange
    <button type="submit">Submit</button>
</form>

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    if(isset($_POST['fruits'])) {
        $selectedFruits = $_POST['fruits'];
        
        foreach($selectedFruits as $fruit) {
            echo $fruit . "<br>";
        }
    }
}
?>