Sorry NYSiRacer for not commenting my code. I usually don't as I am usually pretty busy. I am glad you have asked though.
In the first line, I set up an array with two elements inside it.
• $shade_ar = array("#DDDDDD", "#BBBBBB");
The two elements are the html colours you are alternating. I think you already undersand that so I will move on.
The first line inside the loop is the control variable:
• $shade = !$shade;
Essentially ! means NOT. If you have a variable that is either TRUE (1) or FALSE (0) then you can put a ! in front of it to return the opposite of what it is. By default all variables are a 0 (FALSE) before you do anything with them. So on the first loop we are making $shade the opposite of what shade already is. $shade already is a 0 so on the first pass it makes $shade to be a 1.
The next time the loop goes around, it makes shade the opposite again. $shade is now a 1, therefore $shade becomes a 0 again on the second pass. On the third pass it becomes a 1 and the forth a 0. So essentially $shade just flip flops between 1 and 0 each time $shade = !$shade; is run.
In the next line we have this:
• $shade_ar[$shade]
When you access an array, you do so by asking for the array ($shade_ar) and what element inside it ([$shade]). The first element can be accessed with a 0, and the second with a 1 and so on to the end of the array.
$shade_ar[0] = #DDDDDD
$shade_ar[1] = #BBBBBB
So on the first run, this part returns '#BBBBBB' and on the second '#DDDDDD' and on the third it's back to '#BBBBBB', thus your colours are alternating. It's just a very simple method that I dreamt up when I made my forums, and it's the method I still use: http://www.almostrammstein.com/nf/forums/view_forum.html?fid=1
Feel free to use this code at will. If you find a simpler way, let me know 🙂