How can the foreach loop be utilized to improve the naming convention of form input fields in PHP?

When creating form input fields in PHP, it can be tedious to manually name each input field with a unique identifier. By using a foreach loop, we can dynamically generate these names based on an array of field names, making the code more concise and maintainable.

<?php
// Array of field names
$fields = ['username', 'password', 'email'];

// Loop through the array to create form input fields
foreach ($fields as $field) {
    echo '<input type="text" name="' . $field . '" /><br>';
}
?>