What is the purpose of the dynauswahl function in the PHP code provided?
The dynauswahl function in the PHP code provided is used to dynamically generate a select dropdown menu based on the options passed as an array. The purpose of this function is to simplify the process of creating select dropdown menus with dynamic options in PHP.
function dynauswahl($name, $options, $selected = null) {
$html = '<select name="' . $name . '">';
foreach ($options as $value => $label) {
$html .= '<option value="' . $value . '"';
if ($selected == $value) {
$html .= ' selected';
}
$html .= '>' . $label . '</option>';
}
$html .= '</select>';
return $html;
}
// Example usage
$options = array(
'1' => 'Option 1',
'2' => 'Option 2',
'3' => 'Option 3'
);
echo dynauswahl('my_select', $options, '2');