stefano ricci uses static to realize the color display of tables in alternate rows

WBOY
Release: 2016-07-29 08:34:52
Original
971 people have browsed it

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 feel uncomfortable. 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("

n");//The following outputs 10 lines
for($i=0;$i<10 ;$i++)
{ $bcolor=getcolor();//Change the background color
print("n");
print("n" );
print("");
}
print("
$i
n");
Explanation:
A static variable static $colorvalue is defined in this program, which means that at the end of the function call Afterwards,
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.

The above introduces stefano ricci's use of static to realize the interlaced display of table colors, including the content of stefano ricci. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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