Use static to display the color of a table, read and use static to display the color of a table, and use static to display the color of a table. We use PHP to query data from the database, output the result to the browser. if there are many rows in the result and the bgcolor of the table is all monochrome, the browser will feel uncomfortable. So how to make the table "> <LINKhref =" http: // www use static to display the color of the table in different rows
We use PHP to query data from the database and output the results to the browser. if there are many rows in the results and the bgcolor of the table is all monochrome, the browser will feel uncomfortable. So how can we make the color of each row of the table different?
See the following:
Function getcolor ()
{
Static $ colorvalue; // defines a static variable.
If ($ colorvalue = "# ffffff ")
$ Colorvalue = "#000000 ";
Else $ colorvalue = "# ffffff ";
Return ($ colorvalue );
}
Print ("
N "); // output 10 rows below for ($ I = 0; $ I <10; $ I ++) {$ bcolor = getcolor (); // print ("
N "); print ("
$ I | N "); print ("
");} Print ("
N ");
Note:
This program defines a static variable static $ colorvalue, which means that after the function call ends,
The variable $ colorvalue is retained 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.