如何在switch语句中为输入指定不同的名称,用于显示不同类型的问题

The problem is that if I assign same case type, which is used for different types of question inputs too 2 different question. I am able to only select 1 question at a time. The question types are saved within the database. I think I need to change the name attribute for every input but I am not sure how to do it.

I have tried using a for loop inside the switch statement for a that specific type of input.

for ($i = 0; $i < $n; $i++) 
{
    $row = mysqli_fetch_assoc($result);
    echo <<<_END
    <label for="questions"><h2>{$row['question_id']} 
        {$row['question_body']}</h2></label><br>
_END;
    switch ($row['question_type']) 
    {
       case "DD":
        echo 
    "<select name = 'answer[]'>
       <option>Facebook</option>
       <option >Instagram</option>
       <option>Snapchat</option>
       <option>Other</option>
    </select><br>";
    break;
    case "NI":
         echo "<input type = 'text' pattern= '[0-9]' title = 'Please enter a number between 0-9' name= 'answer[]' required><br>";
    break;
    case "RI":
    echo "<input type = 'radio' name = 'answer[]' value = 'Yes' required>Yes<br>
    <input type = 'radio' name = 'answer[]' value = 'No'>No<br>"; 
    break;
    case "TXT":
    echo "<input type = 'text' name = 'answer[]' required>";
    break;
    case "CB":
    echo "<input type = 'checkbox' name = 'answer[]' value = 'Smart Phone'> Smart Phone<br>
     <input type = 'checkbox' name = 'answer[]' value = 'Laptop'> Laptop<br>
    <input type = 'checkbox' name = 'answer[]' value = 'PC'> PC<br>";
    break;
    }

    echo <<<_END

<input type = 'text' name = 'question_id[]' value='{$row['question_id']}'><br>

_END;}

I do get all the different types of questions but they all have the same name so if I edit case RI, which is for radio input, then all the question types, that are radio inputs will be deselected and only one radio input will be selected inside the form.

Why dont you use some PHP with the strings that make the checkoxes and selects to have unique names for each one of them

for ex.

 echo 
    "<select name = 'answer".$i."[]'>
       <option>Facebook</option>
       <option >Instagram</option>
       <option>Snapchat</option>
       <option>Other</option>
    </select><br>";