What is the correct syntax for handling multiple selections in a PHP form using the select field?

When handling multiple selections in a PHP form using the select field, you need to ensure that the select field has the 'multiple' attribute set. This allows users to select multiple options by holding down the Ctrl key (or Command key on Mac) while clicking on the options. In PHP, you can access the selected values as an array in the $_POST or $_GET superglobals.

<form method="post">
    <select name="colors[]" multiple>
        <option value="red">Red</option>
        <option value="blue">Blue</option>
        <option value="green">Green</option>
    </select>
    <input type="submit" value="Submit">
</form>

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