How can multiple selected options from a select element be read in PHP?

When multiple options are selected from a select element in HTML, they are sent as an array in the form of "name[]" to the server. In PHP, you can access these selected options by using the $_POST or $_GET superglobals depending on the form submission method. You can then loop through the array to process each selected option individually.

<?php
if(isset($_POST['options'])) {
    $selectedOptions = $_POST['options'];
    
    foreach($selectedOptions as $option) {
        echo $option . "<br>";
    }
}
?>

<form method="post">
    <select name="options[]" multiple>
        <option value="option1">Option 1</option>
        <option value="option2">Option 2</option>
        <option value="option3">Option 3</option>
    </select>
    <input type="submit" value="Submit">
</form>