Change color alternately using 4 different colors in PHP

时间:2017-12-18 08:11:37

标签: php html css laravel-5

I did a lot of research about it but I ended up with just using 2 different colors instead of 4. What I want is to change the color alternately using 4 different colors (model->deleteLater(); conn.connClose(); , blue, red, green). What I have is just the two colors. Please see my code below:

yellow

Note: I'm also using laravel 5 for this.

2 个答案:

答案 0 :(得分:2)

you should define array of colors and use colors_counter as the array index.

pickerViewDidSelectRowInComponent

答案 1 :(得分:2)

Simple Scalable Solution

You can have the colors in a separate array and take mod value of the total count to alternate the colors between the rows.

This solution is scalable and will work for /* Create an unsorted CF-query */ unsorted = QueryNew("col1,col2,col3,col4","VarChar,VarChar,Integer,VarChar"); for (a=10;a gte 1;a--){ QueryAddRow(unsorted); QuerySetCell(unsorted,"col1","col1 #a#"); QuerySetCell(unsorted,"col2","col2 #a#"); QuerySetCell(unsorted,"col3","#a#"); QuerySetCell(unsorted,"col4","col4 #a#"); } writeDump(var="#unsorted#"); /* Create a new CF query of query with the unsorted table */ sorted = new query( dbtype = "query" ,unsorted = unsorted ,sql = "select [col1],[col2] from unsorted order by [col3], [col4] asc" ).execute().getresult(); /* The last column in the order by list will be displayed in the result */ writeDump(var="#sorted#", label="sorted"); selected = new query( dbtype = "query" ,sorted = sorted ,sql = "select [col1],[col2] from sorted" ).execute().getresult(); number of colors across N number of rows.

This way, the code will work even if you modify the number of colors or rows.

Scalable Code Logic

M

Example

$colors = [
    'blue'
    'red',
    'green',
    'yellow',
];
$no = count($colors);

// Then use this inside the loop
$colors[$colors_counter % $no];

Output

$colors = [
    'blue',
    'red',
    'green',
    'yellow',
];

$no = count($colors);

for ($i=0;$i < 10; $i++) {
  echo $colors[$i % $no]."\n";  
}
相关问题