Home > php教程 > php手册 > body text

利用static实现表格的颜色隔行显示

WBOY
Release: 2016-06-13 12:37:30
Original
788 people have browsed it

利用static实现表格的颜色隔行显示

我们用PHP从数据库查询数据,并将结果输出到浏览器上,如果结果有很多行,表格的bgcolor如果全是单色的,浏览者会感觉不太舒服。那麽怎样做使表格各行的颜色不同呢?
请看下面:

function getcolor()
{
static $colorvalue;//定义一个静态变量
if($colorvalue=="#ffffff")
$colorvalue="#000000";
else $colorvalue="#ffffff";
return($colorvalue);
}

print("

n");//下面输出10行
for($i=0;$i{ $bcolor=getcolor();//换背景颜色
print("n");
print("n");
print("");
}
print("
$i
n");
说明:
此程序中定义了一个静态变量static $colorvalue意思是在函数调用结束后,
此变量$colorvalue还保留值,没有消失。当再次调用getcolor()函数时,变量$colorvalue的值是上次函数调用结束时$colorvalue的值。
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!