我有几个变量,在我增加数字后,它只显示$ bgcolor1。但我希望它写出来:bgcolor ='#0066CC'。 我只是无法弄清楚解决方案。 希望可以有人帮帮我。 谢谢!
$bgcolor1 = "bgcolor='#0066CC'";
$bgcolor2 = "bgcolor='#FF0000'";
$bgcolor3 = "bgcolor='#00FF00'";
for ($c = 1; $c <=5; $c++){
print "<table border='1' ".'$bgcolor'.$c.">";
}
答案 0 :(得分:1)
试试这个:
$bgcolor1 = "bgcolor='#0066CC'";
$bgcolor2 = "bgcolor='#FF0000'";
$bgcolor3 = "bgcolor='#00FF00'";
for ($c = 1; $c <=5; $c++){
$bgcolor = "{$bgcolor}{$c}";
print "<table border='1' ". $bgcolor . ">";
}
答案 1 :(得分:0)
尝试将颜色放入数组中,然后循环遍历数组并打印出来。
$bgcolors = array("bgcolor='#0066CC'", "bgcolor='#FF0000'", "bgcolor='#00FF00'");
for ($c = 0; $c < 3; $c++){
print "<table border='1' " . $bgcolors[$c] . ">";
}
答案 2 :(得分:0)
$bgcolor1 = "bgcolor='#0066CC'";
$bgcolor2 = "bgcolor='#FF0000'";
$bgcolor3 = "bgcolor='#00FF00'";
for ($c = 1; $c <=5; $c++){
print "<table border='1' ".${"bgcolor".$c}.">";
}