Using static to realize the color interlaced display of the table
We use PHP to query data from the database, and output the results to the browser, if the result has a lot of rows, the table bgcolor if all is monochrome, the viewer will not feel very comfortable. So what do you do to make the table rows different colors?
Please see below:
function GetColor ()
{
static $colorvalue;//define a static variable
if ($colorvalue = = "#ffffff")
$colorvalue = "#000000";
else $colorvalue = "#ffffff";
return ($colorvalue);
}
Print ("
n ")///output 10 lines for ($i =0; $i <10; $i + +) {$bcolor =getcolor ();//change background color print ("
n "); Print ("
$i | n "); Print ("
"); } Print ("
n ");
Description
A static variable is defined in this program $colorvalue meaning that after the function call ends,
This variable $colorvalue also retains the value and does not disappear. When you call the GetColor () function again, the value of the variable $colorvalue is the value $colorvalue at the end of the last function call.
http://www.bkjia.com/PHPjc/316789.html www.bkjia.com true http://www.bkjia.com/PHPjc/316789.html techarticle using the static implementation of the table color interlaced display we use PHP to query data from the database, and output the results to the browser, if the result has a lot of rows, the table bgcolor if it is all monochrome ...