How can different columns be dynamically displayed in a table without having to edit the script when new tasks are added?

To dynamically display different columns in a table without editing the script when new tasks are added, you can store the column names in an array and iterate over them to generate the table headers and data. This way, when new tasks are added, you only need to update the column names array without changing the script.

<?php

// Array of column names
$columns = ['Task Name', 'Assigned To', 'Due Date'];

// Sample data for tasks
$tasks = [
    ['Task 1', 'John Doe', '2022-01-15'],
    ['Task 2', 'Jane Smith', '2022-01-20'],
    ['Task 3', 'Mike Johnson', '2022-01-25']
];

// Display table headers
echo '<table>';
echo '<tr>';
foreach ($columns as $column) {
    echo '<th>' . $column . '</th>';
}
echo '</tr>';

// Display table data
foreach ($tasks as $task) {
    echo '<tr>';
    foreach ($task as $data) {
        echo '<td>' . $data . '</td>';
    }
    echo '</tr>';
}

echo '</table>';

?>