How can dropdown menus be populated with values from XML in PHP?

To populate dropdown menus with values from XML in PHP, you can use PHP's SimpleXML extension to parse the XML data and extract the values you want to populate the dropdown menu with. You can then loop through the extracted values and generate the HTML options for the dropdown menu.

<?php
// Load XML file
$xml = simplexml_load_file('data.xml');

// Extract values for dropdown menu
$values = [];
foreach ($xml->item as $item) {
    $values[] = (string) $item->value;
}

// Generate dropdown menu
echo '<select>';
foreach ($values as $value) {
    echo '<option>' . $value . '</option>';
}
echo '</select>';
?>