How can PHP be used to check if a table cell is empty and hide the corresponding table header if it is?

To check if a table cell is empty in PHP and hide the corresponding table header if it is, you can iterate through the table rows and check if the cell is empty. If it is empty, you can add a CSS class to hide the corresponding table header.

<?php
// Assuming $tableData is a 2D array containing the table data
foreach($tableData as $row) {
    if(empty($row[$cellIndex])) {
        echo '<style>.table th:nth-child('.($cellIndex+1).') { display: none; }</style>';
    }
}
?>