What are some best practices for displaying the output of a PHP script in a table format?

When displaying the output of a PHP script in a table format, it is best practice to use HTML table tags to structure the data. This makes the information easier to read and understand for users. To do this, you can loop through an array of data and output each element within table row and cell tags.

<?php
// Sample data array
$data = array(
    array('Name' => 'John Doe', 'Age' => 30, 'Email' => 'john.doe@example.com'),
    array('Name' => 'Jane Smith', 'Age' => 25, 'Email' => 'jane.smith@example.com'),
    array('Name' => 'Alice Johnson', 'Age' => 35, 'Email' => 'alice.johnson@example.com')
);

// Display data in a table format
echo '<table border="1">';
echo '<tr><th>Name</th><th>Age</th><th>Email</th></tr>';
foreach ($data as $row) {
    echo '<tr>';
    echo '<td>' . $row['Name'] . '</td>';
    echo '<td>' . $row['Age'] . '</td>';
    echo '<td>' . $row['Email'] . '</td>';
    echo '</tr>';
}
echo '</table>';
?>