How can using the same names from a database in multiple dropdowns or radio inputs in PHP be achieved without encountering issues like only displaying them once?

When using the same names from a database in multiple dropdowns or radio inputs in PHP, one way to avoid issues like only displaying them once is to append a unique identifier to each name. This can be achieved by adding a counter or a random string to the name to make it unique for each dropdown or radio input.

<?php
// Fetch names from database
$names = array("John", "Jane", "Alice", "Bob");

// Counter for unique identifier
$counter = 1;

// Display dropdowns with unique names
foreach($names as $name){
    echo "<select name='name_$counter'>";
    echo "<option value='$name'>$name</option>";
    echo "</select>";
    
    $counter++;
}
?>