How can the PHP code be optimized for handling multiple entries and dynamically assigning email addresses based on input data?

To optimize PHP code for handling multiple entries and dynamically assigning email addresses based on input data, we can use arrays to store the input data and loop through each entry to generate the email addresses dynamically. This approach allows for scalability and flexibility when processing large amounts of data.

<?php

// Sample input data
$input_data = [
    ['first_name' => 'John', 'last_name' => 'Doe'],
    ['first_name' => 'Jane', 'last_name' => 'Smith'],
    // Add more entries as needed
];

// Loop through each entry to generate email addresses
foreach ($input_data as $entry) {
    $email = strtolower($entry['first_name'] . '.' . $entry['last_name'] . '@example.com');
    echo "Generated email address for {$entry['first_name']} {$entry['last_name']}: $email\n";
}

?>