if I have a for loop : for ($i=0; $i<count($replyDetails); $i++){ ... bgcolor = 123 (OR 456)... ... } and will show bgcolor = 123 if $i is an even number or $i=0 and will show bgcolor = 456 if $i is an odd number
how can i implement that?
This is something you can use the mod operator (%) for.
if ($i%2==0) {// $i is even $bgcolor = 123; } else {// $i is odd $bgcolor = 456; }
As the example shows, just set a variable for the background colour appropriately in each branch.
if ($i % 2 == 0) { echo "123"; } else { echo "456"; }
The % is the mod operator, it just returns the remainder. The remainder of an even number divided by two is always equal to zero.
Hope this helps.