What are common methods for styling alternating rows in a PHP-generated table?

Styling alternating rows in a PHP-generated table can improve readability and visual appeal. One common method to achieve this is by using CSS to apply different background colors to odd and even rows. This can be done by adding a conditional statement in the PHP code to determine if a row is odd or even, and then assigning a corresponding CSS class to style the rows accordingly.

<table>
<?php
$data = array("Row 1", "Row 2", "Row 3", "Row 4", "Row 5");

foreach($data as $key => $value) {
    $row_class = ($key % 2 == 0) ? 'even' : 'odd';
    echo "<tr class='$row_class'><td>$value</td></tr>";
}
?>
</table>

<style>
.even {
    background-color: #f2f2f2;
}
.odd {
    background-color: #ffffff;
}
</style>