hello… i’m beginner, and i didn’t understand, why when i add i++ then all is in red or in blue color…
like
player1 (blue)
player2 (blue)
player3 (blue)
or
player1 (red)
player2 (red…
i need to get
player1 (blue)
player2 (red)
player3 (blue)
player4 (red…
here is code…
if ($players) foreach ($players as $player => $kills) {
# TRYING TO ADD ADDING i++ colors for all..
for ( $i = 0; $i < count( $players ); $i++ ) {
$color = $i%2 ? 'blue' : 'red';
}
if ($player == "boxer") echo "<div style=\\"float:left;display:inline;color:$color\\">{$player}</div> <div style=\\"float:right;display:inline\\">admin</div>\
";
else echo "<div style=\\"float:left;display:inline;color:$color\\">{$player}</div> <div style=\\"float:right;display:inline\\">[{$kills}]</div>\
";
}
Right now, you have a for loop inside the foreach loop, and all it does is loop through the entire players array and change the value of $color. So in the end if the number of values in $players is even, the color will always be blue, else it will always be red (or the other way around… ).