Php 如何对while或for循环中的变量静态值求和?
可以在while或for循环中对变量静态值进行求和吗?我有代码并正在编写它,但它只对变量求和一次 例如,我希望这样 我需要对每个结果求和Php 如何对while或for循环中的变量静态值求和?,php,variables,sum,Php,Variables,Sum,可以在while或for循环中对变量静态值进行求和吗?我有代码并正在编写它,但它只对变量求和一次 例如,我希望这样 我需要对每个结果求和b值 这里是我的代码 <?php $a='10'; $b='20'; $i=0; while($i <=10) { $c=$c=$a+$b; $i++; ?> <input type="text" value="<?php echo $c[$i] ?>" /> <?php }?> 这里有一个简单的循环
b值
这里是我的代码
<?php
$a='10';
$b='20';
$i=0;
while($i <=10)
{
$c=$c=$a+$b;
$i++;
?>
<input type="text" value="<?php echo $c[$i] ?>" />
<?php }?>
这里有一个简单的循环
$a = '10';
$b = '20';
$c = 0;
$t = 10;
while($t --) {
printf("<input type=\"text\" value=\"%s\" />", $c += $a + $b);
}
$a='10';
$b='20';
$c=0;
$t=10;
而($t--){
printf(“,$c+=$a+$b”);
}
将$c
设置为某个值,然后加上我不明白你想加10+20 10次吗?与(10+20)*10不一样?@GGio是的如果$c=10+20=30
那么“$c=30+10+20=60”我想要这个?为什么循环?你能不能只做($a+b)*$i
?如果30+30+10+20,那么如果60+60+50+40+30+20+10……,这会持续多久?我想了多长时间……你到底想做什么?我想那不是他想要的:D@GGio你认为他想要什么?看我的答案我想那是他想要的就像我说的。。他不需要任何循环,每次都需要打印输入元素
<?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++;
}
<?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++;
}