php - How to use the for double-layer loop to control the color-changing table of alternate rows
滿天的星座
滿天的星座 2017-05-16 13:00:06
0
2
963

I am a newbie in PHP, please help me to answer this question (◐﹏◐)
A single layer loop is as follows:

The rendering is as follows:

I would like to ask how to use the double-layer loop of for to get the same effect picture as above?

滿天的星座
滿天的星座

reply all(2)
巴扎黑
echo '<table border="1">';
for($i = 1; $i < 10; $i++) {
    echo $i%2 === 0 ? '<tr bgcolor="#ccc">' : '<tr>';
    for($j = 1; $j < 5; $j++) {
        echo "<td>$i$j</td>";
    }
    echo '</tr>';
}
echo '</table>';

In fact, writing this in php is a waste of resources. In actual projects, it is recommended to use the CSS3 pseudo-class nth-child to complete this function

伊谢尔伦

I suggest you take a look at how bootstrap handles the color change of each row. Take a look at its table part

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template