I have a couple of variables, and after I increase the numbers, it only shows $bgcolor1. But I want that it write out this: bgcolor='#0066CC'. I just cannot figure out the solution. Hope someone can help me. Thanks!
$bgcolor1 = "bgcolor='#0066CC'";
$bgcolor2 = "bgcolor='#FF0000'";
$bgcolor3 = "bgcolor='#00FF00'";
for ($c = 1; $c <=5; $c++){
print "<table border='1' ".'$bgcolor'.$c.">";
}
$bgcolor1 = "bgcolor='#0066CC'";
$bgcolor2 = "bgcolor='#FF0000'";
$bgcolor3 = "bgcolor='#00FF00'";
for ($c = 1; $c <=5; $c++){
print "<table border='1' ".${"bgcolor".$c}.">";
}
Try this:
$bgcolor1 = "bgcolor='#0066CC'";
$bgcolor2 = "bgcolor='#FF0000'";
$bgcolor3 = "bgcolor='#00FF00'";
for ($c = 1; $c <=5; $c++){
$bgcolor = "{$bgcolor}{$c}";
print "<table border='1' ". $bgcolor . ">";
}
Try putting the colors in an array, then looping over the array and printing them out.
$bgcolors = array("bgcolor='#0066CC'", "bgcolor='#FF0000'", "bgcolor='#00FF00'");
for ($c = 0; $c < 3; $c++){
print "<table border='1' " . $bgcolors[$c] . ">";
}