What is the purpose of the multiple selection list in PHP and how is it populated from an array?
The purpose of a multiple selection list in PHP is to allow users to select multiple options from a list. To populate a multiple selection list from an array, you can use a foreach loop to iterate over the array and create an option element for each item in the array.
<select name="options[]" multiple>
<?php
$options = array("Option 1", "Option 2", "Option 3");
foreach($options as $option) {
echo "<option value='$option'>$option</option>";
}
?>
</select>
Keywords
Related Questions
- What are the potential pitfalls of passing sessions via URL parameters in PHP for server-to-server communication?
- What potential issues can arise when using the date() function in PHP to get the day of the week?
- How can PHP developers troubleshoot and debug session variable issues in different browsers such as Safari and Internet Explorer?