This question already has an answer here:
With this code:
$html .= "
<input type='text' name='participant[" . $k . "][answer]'
class='form-control'" . ($required ? " required" : ""). ">";
The generated input is like:
<input type='text'
name='participant[1][answer]' class='form-control' required>
Do you know how to have "" instead of ''? Like:
<input type="text" name="participant[1][answer]" class="form-control" required>
</div>
You would need to escape the quotation marks with backslashes:
$html .= "
<input type=\"text\" name=\"participant[" . $k . "][answer]\"
class=\"form-control\"" . ($required ? " required" : ""). ">";
However, note that there is absolutely no difference between the two; they'll still be processed the same way.
Note that PHP variables will be evaluated inside double quotes (and not single quotes), so you could even shrink this down to the following equivalent code:
$html .= "
<input type=\"text\" name=\"participant[$k][answer]\"
class=\"form-control\"" . ($required ? " required" : ""). ">";