How can you create a table in PHP to display names and entry dates, with the ability to group names by date?

To display names and entry dates in a table grouped by date in PHP, you can achieve this by first sorting the data by date and then looping through the sorted data to display each name under the corresponding date. You can use an associative array to group names by date and then iterate over the array to output the table.

<?php
// Sample data array with names and entry dates
$data = array(
    array('name' => 'Alice', 'date' => '2022-01-01'),
    array('name' => 'Bob', 'date' => '2022-01-01'),
    array('name' => 'Charlie', 'date' => '2022-01-02'),
    array('name' => 'David', 'date' => '2022-01-02'),
);

// Group names by date
$groupedData = array();
foreach ($data as $entry) {
    $groupedData[$entry['date']][] = $entry['name'];
}

// Output the table
echo '<table>';
foreach ($groupedData as $date => $names) {
    echo '<tr><th colspan="2">' . $date . '</th></tr>';
    foreach ($names as $name) {
        echo '<tr><td>' . $name . '</td></tr>';
    }
}
echo '</table>';
?>