In what scenarios does using a table class in PHP make sense, and how does it compare to other template systems for HTML output?

Using a table class in PHP makes sense when you need to generate HTML tables dynamically with data from a database or other sources. It can help you structure and style your tables consistently across your website. Compared to other template systems for HTML output, using a table class in PHP allows for more flexibility and customization in generating and styling tables.

<?php
class Table {
    private $data;

    public function __construct($data) {
        $this->data = $data;
    }

    public function generateTable() {
        $html = '<table>';
        foreach($this->data as $row) {
            $html .= '<tr>';
            foreach($row as $cell) {
                $html .= '<td>' . $cell . '</td>';
            }
            $html .= '</tr>';
        }
        $html .= '</table>';

        return $html;
    }
}

// Example usage
$data = [
    ['John', 'Doe', 'john.doe@example.com'],
    ['Jane', 'Smith', 'jane.smith@example.com'],
];

$table = new Table($data);
echo $table->generateTable();
?>