Stefano Ricci using static to realize the color interlaced display of the table

Source: Internet
Author: User
Tags getcolor
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 (" n "); Print (" "); } Print ("
$i
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.

  • Related Article

    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.