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

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

Jun 13, 2016 pm 12:31 PM
static code use Function exist accomplish actual right application us show of programming sheet alternate lines color

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Remove duplicate values ​​from PHP array using regular expressions Remove duplicate values ​​from PHP array using regular expressions Apr 26, 2024 pm 04:33 PM

Remove duplicate values ​​from PHP array using regular expressions

Vivo's new X100 series memory, color exposure: all series start at 12+256GB Vivo's new X100 series memory, color exposure: all series start at 12+256GB May 06, 2024 pm 03:58 PM

Vivo's new X100 series memory, color exposure: all series start at 12+256GB

Tsinghua University and Zhipu AI open source GLM-4: launching a new revolution in natural language processing Tsinghua University and Zhipu AI open source GLM-4: launching a new revolution in natural language processing Jun 12, 2024 pm 08:38 PM

Tsinghua University and Zhipu AI open source GLM-4: launching a new revolution in natural language processing

Samsung will provide displays for Microsoft's MR headsets, and the devices are expected to be lighter and have clearer displays Samsung will provide displays for Microsoft's MR headsets, and the devices are expected to be lighter and have clearer displays Aug 10, 2024 pm 09:45 PM

Samsung will provide displays for Microsoft's MR headsets, and the devices are expected to be lighter and have clearer displays

What is GateToken(GT) currency? Introduction to GT coin functions and token economics What is GateToken(GT) currency? Introduction to GT coin functions and token economics Jul 15, 2024 pm 04:36 PM

What is GateToken(GT) currency? Introduction to GT coin functions and token economics

The Mistral open source code model takes the throne! Codestral is crazy about training in over 80 languages, and domestic Tongyi developers are asking to participate! The Mistral open source code model takes the throne! Codestral is crazy about training in over 80 languages, and domestic Tongyi developers are asking to participate! Jun 08, 2024 pm 09:55 PM

The Mistral open source code model takes the throne! Codestral is crazy about training in over 80 languages, and domestic Tongyi developers are asking to participate!

What is programming for and what is the use of learning it? What is programming for and what is the use of learning it? Apr 28, 2024 pm 01:34 PM

What is programming for and what is the use of learning it?

The Key to Coding: Unlocking the Power of Python for Beginners The Key to Coding: Unlocking the Power of Python for Beginners Oct 11, 2024 pm 12:17 PM

The Key to Coding: Unlocking the Power of Python for Beginners

See all articles