What is the best practice for using while loops to generate option tags within a select tag in PHP?

When using while loops to generate option tags within a select tag in PHP, it is important to ensure that the loop iterates through a dataset and generates the desired options dynamically. This can be achieved by fetching data from a database or an array and using a while loop to iterate through the data and generate option tags for each item. It is also important to properly structure the HTML output within the loop to ensure that each option tag is correctly formatted.

<select name="items">
<?php
// Assume $items is an array of items
$items = ["Item 1", "Item 2", "Item 3"];

// Use a while loop to generate option tags for each item
foreach($items as $item) {
    echo "<option value='$item'>$item</option>";
}
?>
</select>