How can PHP be used to dynamically generate input fields in a form for editing contact data?

To dynamically generate input fields in a form for editing contact data, we can use PHP to loop through the contact data and create input fields based on the number of contacts. This allows us to easily display and edit multiple contact entries in a form.

<?php
// Sample contact data
$contacts = array(
    array('name' => 'John Doe', 'email' => 'john@example.com'),
    array('name' => 'Jane Smith', 'email' => 'jane@example.com')
);

// Loop through the contact data and generate input fields
foreach ($contacts as $index => $contact) {
    echo '<input type="text" name="contacts['.$index.'][name]" value="'.$contact['name'].'"><br>';
    echo '<input type="email" name="contacts['.$index.'][email]" value="'.$contact['email'].'"><br><br>';
}
?>