Can you use static to display the color of the table in alternate rows?
We use PHP to query data from the database and output the results to the browser. If the results have 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");//Output 10 lines below
for($i=0;$i<10;$i++)
{ $bcolor=getcolor();//Change the background color
print("n");
print("$i | n");
print("
");
}
print("
n");
Description:
A static variable static $colorvalue is defined in this program, which means that after the function call is completed,
This variable $colorvalue still retains its value and has not disappeared. 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 whether you can use static to realize the color display of tables in alternate rows, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.