ul? Li? List style:? None; ? Width:? 20%; ? Floating:? Left; }. Red? Color:? # ff0000}. Blue {? Color" />

Job Recruitment Website - Job information - How to change the color of every 5 pieces of data with PHP

How to change the color of every 5 pieces of data with PHP

& lt style? type="text/css " >

ul? Li? List style:? None; ? Width:? 20%; ? Floating:? Left; }

. Red? Color:? # ff0000}

. Blue {? Color:? # 0000ff}

& lt/style & gt;

& ltdiv & gt

& ltul & gt

& lt? Server-side programming language (abbreviation of professional hypertext preprocessor)

$array? =? Array ('1',? ' 1',? ' 1',? ' 1',? ' 1',? '2',? '2',? '2',? '2',? '2',? '3');

foreach($array? As? $ key = & gt$val){

$style? =? $key/5%2? ==? 0? class="red " '? :? class = " blue " ';

& gt

& lt Li? & lt? php? echo($ style); & gt& gt& lt? php? echo($ val); & gt& lt/ Li>

& lt? Server-side programming language (abbreviation of professional hypertext preprocessor)

}

& gt

& lt/ul & gt;

& lt/div & gt; This effect can be judged by the value of $key.

First, divide the quotient obtained by 5 by the value of $key, which can be understood as the number of rows, that is, the elements displayed in the first row with the quotient of $key/5 of 0, and so on.

Because every two lines will change color, so

Then use the obtained quotient to find the remainder divided by 2,

Assign styles to single and double lines

You can specify another style after the line is finished.