利用static实现表格的颜色隔行显示的代码
Jun 13, 2016 pm 12:31 PM
在实际编程应用中我们对STATIC的功能经常遗忘。要好好反省。。:)
我们用PHP从数据库查询数据,并将结果输出到浏览器上,如果结果有很多行,表格的bgcolor如果全是单色的,浏览者会感觉不太舒服。那麽怎样做使表格各行的颜色不同呢?
请看下面:
复制代码 代码如下:
function getcolor()
{
static $colorvalue;//定义一个静态变量
if($colorvalue=="#ffffff")
$colorvalue="#000000";
else $colorvalue="#ffffff";
return($colorvalue);
}
print("
$i | n");
?>
说明:
此程序中定义了一个静态变量static $colorvalue意思是在函数调用结束后,
此变量$colorvalue还保留值,没有消失。当再次调用getcolor()函数时,变量$colorvalue的值是上次函数调用结束时$colorvalue的值。

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Remove duplicate values from PHP array using regular expressions

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

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

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?

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