Use static to display the color of a table in different rows

Source: Internet
Author: User
Use static to display the color interrows of a table. use static to display the color interrows of a table.

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 (" N "); print (" ");} Print ("
$ I
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.