How can the code snippet provided in the forum thread be optimized to efficiently handle multiple categories in the pulldown menu?

The code snippet provided in the forum thread can be optimized by using a multidimensional array to store the categories and subcategories. This will allow for efficient handling of multiple categories in the pulldown menu. Each category can have an array of subcategories associated with it, making it easier to organize and display the menu options.

$categories = array(
    'Category 1' => array('Subcategory 1', 'Subcategory 2', 'Subcategory 3'),
    'Category 2' => array('Subcategory 1', 'Subcategory 2', 'Subcategory 3'),
    'Category 3' => array('Subcategory 1', 'Subcategory 2', 'Subcategory 3')
);

echo '<select name="category">';
foreach ($categories as $category => $subcategories) {
    echo '<optgroup label="' . $category . '">';
    foreach ($subcategories as $subcategory) {
        echo '<option value="' . $subcategory . '">' . $subcategory . '</option>';
    }
    echo '</optgroup>';
}
echo '</select>';