这对while或for循环中的sum variable static values
可能吗?我有代码,正在处理它,但它只sum variables
一次?
例如,我想要这样
我需要将b values
与每个结果相加?
这里是我的代码
<?php
$a='10';
$b='20';
$i=0;
while($i <=10)
{
$c=$c=$a+$b;
$i++;
?>
<input type="text" value="<?php echo $c[$i] ?>" />
<?php }?>
<?php
$a = '10';
$b = '20';
$c = '0';
$i = 0;
while ($i <= 10) {
$c = (int)$a + (int)$b + (int)$c;
//your html input element with the value of c
echo '<input type="text" value="' . $c . '" />';
$i++;
}
当$i = 0
时,结果将是10 + 20 + 0 = 30
,并且输入元素的值30
当$i = 1
时,结果将是10 + 20 + 30 = 60
,并且输入元素的值60
当$i = 2
时,结果将是10 + 20 + 60 = 90
,并且输入元素的值90
等等。。。
这里有一个简单的循环
$a = '10';
$b = '20';
$c = 0;
$t = 10;
while($t --) {
printf("<input type="text" value="%s" />", $c += $a + $b);
}
<?php
$a='10';
$b='20';
$c = 0;
$i=0;
while($i <=10)
{
$c=$c+$a+$b;
$sum=$c+$b;
$i++;
?>
将$c
设置为某个值,然后添加