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.
The above describes the Stefano Ricci the use of static implementation of the table color interlaced display, including the Stefano Ricci aspects of the content, I hope that the PHP tutorial interested in a friend helpful.