Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何对while或for循环中的变量静态值求和?_Php_Variables_Sum - Fatal编程技术网

Php 如何对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 }?> 这里有一个简单的循环

可以在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 }?>

这里有一个简单的循环

$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++;
  }