What are the potential benefits of using a helper function in PHP to create dropdown lists?

When creating dropdown lists in PHP, using a helper function can streamline the process and make the code more reusable. This can help reduce code duplication and make it easier to maintain and update the dropdown lists throughout the application.

function createDropdown($options, $selectedValue) {
    $dropdown = '<select>';
    foreach($options as $value => $text) {
        $selected = ($selectedValue == $value) ? 'selected' : '';
        $dropdown .= '<option value="' . $value . '" ' . $selected . '>' . $text . '</option>';
    }
    $dropdown .= '</select>';
    return $dropdown;
}

// Example usage
$options = array(
    '1' => 'Option 1',
    '2' => 'Option 2',
    '3' => 'Option 3'
);
$selectedValue = '2';
echo createDropdown($options, $selectedValue);