search
Homephp教程php手册利用static实现表格的颜色隔行显示的代码

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

Jun 13, 2016 pm 12:31 PM
staticcodeuseFunctionexistaccomplishactualrightapplicationusshowofprogrammingsheetalternate linescolor

在实际编程应用中我们对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的值。 
Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function