What are the potential challenges of modifying the array of fetched fields in PHP before generating an HTML table?

Modifying the array of fetched fields in PHP before generating an HTML table can be challenging because it may require restructuring the data and potentially altering the table structure. One way to solve this issue is to create a new array with the modified fields and then use that array to generate the HTML table.

<?php

// Fetch data from database
$data = [
    ['id' => 1, 'name' => 'John Doe', 'age' => 30],
    ['id' => 2, 'name' => 'Jane Smith', 'age' => 25],
];

// Modify the fetched fields
$modifiedData = [];
foreach ($data as $row) {
    $modifiedData[] = [
        'ID' => $row['id'],
        'Full Name' => $row['name'],
        'Age' => $row['age'],
    ];
}

// Generate HTML table
echo '<table>';
echo '<tr><th>ID</th><th>Full Name</th><th>Age</th></tr>';
foreach ($modifiedData as $row) {
    echo '<tr>';
    echo '<td>' . $row['ID'] . '</td>';
    echo '<td>' . $row['Full Name'] . '</td>';
    echo '<td>' . $row['Age'] . '</td>';
    echo '</tr>';
}
echo '</table>';

?>