What are the advantages and disadvantages of using for loops versus if statements in PHP for dynamically generating form fields?

When dynamically generating form fields in PHP, using a for loop is advantageous because it allows you to easily create a specified number of form fields without repeating code. On the other hand, using if statements can be more cumbersome and error-prone when dealing with a large number of form fields. However, if statements can be useful for conditionally displaying certain form fields based on user input or other factors.

// Using a for loop to dynamically generate form fields
$num_fields = 5;

for ($i = 1; $i <= $num_fields; $i++) {
    echo "<input type='text' name='field_$i'><br>";
}