How can PHP arrays and loops be used to automate the creation of columns in a table?

To automate the creation of columns in a table using PHP arrays and loops, you can define an array of column names and then use a loop to iterate over the array and generate the corresponding table columns dynamically. This approach allows for easy scalability and maintenance of the table structure.

<?php
$columns = array("Name", "Age", "City");

echo "<table>";
echo "<tr>";
foreach ($columns as $column) {
    echo "<th>$column</th>";
}
echo "</tr>";
echo "</table>";
?>