时间: 2021-07-31 作者:daque
一个颜色轮换的简单例子,运用三元演算子,使步调简单。 咱们已经在网站上看过少许表格单位格的后台脸色是隔行变革的,本来用底下一段很小的一段代码就不妨实行: $color=(($coloralter++ %2)? "e0e0e0":"e8e8e8") ,即经过将变量累加和2取余,应用三元演算子来博得两个各别得脸色值。 示比方下: <html> <head> <title>test</title> <meta http-equiv="content-type" content="text/html; charset=utf8"> </head> <body bgcolor="#ffffff"> <table width="750" border="0" cellspacing="1" cellpadding="1"> <?php for ($i=0;$i<5;$i++) { $color = (($coloralternator++ %2) ? "e0e0e0" : "ff6666"); echo "<tr bgcolor='".$color."'><td>大师好</td></tr>"; } ?> </table> </body> </html>