What is the best practice for structuring forms in PHP to display questions individually?
When structuring forms in PHP to display questions individually, it is best practice to use a loop to iterate through an array of questions and display each question one at a time. This approach allows for better organization of the form and makes it easier to manage the data submitted by the user.
<?php
// Array of questions
$questions = array(
"What is your name?",
"What is your age?",
"What is your favorite color?"
);
// Display questions individually
foreach ($questions as $question) {
echo "<label>$question</label><br>";
echo "<input type='text' name='$question'><br><br>";
}
?>