Home  >  Article  >  Backend Development  >  Use static to realize the color display of tables in alternate rows_PHP tutorial

Use static to realize the color display of tables in alternate rows_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 16:01:45947browse

Use static to realize the color display of the table in alternate rows

We use PHP to query the data from the database and output the results to the browser. If the result has many rows and the bgcolor of the table is all monochrome, the viewer will Not feeling very well. So how to make the colors of each row of the table different?
Please see below:
function getcolor()
{
static $colorvalue;//Define a static variable
if($colorvalue=="#ffffff" )
$colorvalue="#000000";
else $colorvalue="#ffffff";
return($colorvalue);
}

print("< table border =1>n");//Output 10 lines below
for($i=0;$i<10;$i++)
{ $bcolor=getcolor();//Change the background color
print("n");
print("$in");
print("");
}
print("n");
Explanation:
A static variable static $colorvalue is defined in this program, which means that after the function call ends,
this variable $colorvalue still retains its value and does not disappear. When the getcolor() function is called again, the value of the variable $colorvalue is the value of $colorvalue at the end of the last function call.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/316789.htmlTechArticleUse static to realize the color display of tables in alternate rows. We use PHP to query data from the database and output the results to the browser. , if the result has many rows, if the bgcolor of the table is all monochrome...
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