Home >Backend Development >PHP Tutorial >A simple example of color rotation_PHP tutorial

A simple example of color rotation_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 16:02:11839browse

A simple example of color rotation, using the ternary operator to make the program concise.
We have seen on the website that the background color of some table cells changes every other row. In fact, this can be achieved with the following small piece of code: $color=(($coloralter++ %2)? "e0e0e0": "e8e8e8"), that is, by accumulating variables and taking the remainder 2, using the ternary operator to obtain two different color values.
An example is as follows:


test






for ($i=0;$i<5;$i++) {
$color = (( $coloralternator++ %2) ? "e0e0e0" : "ff6666");
echo "}
?>
Hello everyone




www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/316593.htmlTechArticleA simple example of color rotation, using the ternary operator to make the program concise. We have seen on the website that the background color of some table cells changes every other row. In fact, use the following method...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn