How can the correct values be passed for checkboxes in PHP when selecting multiple products for a customer?

When selecting multiple products for a customer using checkboxes in PHP, the correct values can be passed by ensuring that the checkboxes have unique names and using an array to store the selected values. This way, when the form is submitted, you can access the selected values as an array in PHP.

<form method="post" action="process.php">
    <input type="checkbox" name="products[]" value="product1"> Product 1
    <input type="checkbox" name="products[]" value="product2"> Product 2
    <input type="checkbox" name="products[]" value="product3"> Product 3
    <input type="submit" value="Submit">
</form>

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