How can a multiple selection menu be created in PHP that dynamically populates options from an array?

To create a multiple selection menu in PHP that dynamically populates options from an array, you can use a foreach loop to iterate over the array and generate option elements for each value. This allows for a flexible and scalable way to populate the menu with options based on the contents of the array.

<select name="options[]" multiple>
<?php
$options = ['Option 1', 'Option 2', 'Option 3', 'Option 4'];

foreach ($options as $option) {
    echo "<option value='$option'>$option</option>";
}
?>
</select>