Php 而循环直到达到数字

Php 而循环直到达到数字,php,Php,我想做这样的事情 $x = 630; $y = 10; while ($y < $x){ // do something $y+10; } $x=630; $y=10; 而($y

我想做这样的事情

$x = 630;
$y = 10;

while ($y < $x){
// do something
$y+10;
}
$x=630;
$y=10;
而($y<$x){
//做点什么
$y+10;
}

当我使用
$y++
时,它工作并添加+1,但使用+10时它不工作。但我需要走+10步。有什么建议吗

在代码中,您没有增加
$y
$y+10
返回
$y
10
的值,但需要将其分配给
$y

您可以通过以下几种方式完成:

  • $y=$y+10
  • $y+=10
例如:

$x = 630;
$y = 10;
while ($y < $x){
    // do something
    $y = $y + 10;
}
$x=630;
$y=10;
而($y<$x){
//做点什么
$y=$y+10;
}

这是因为$y++相当于$y=$y+1;您没有在$y中指定新值。请试一试

$y += 10;

//用说明注释代码
$x=630;//初始化x
$y=10;//初始化y
而($y<$x){//检查x是否大于y。如果大于,则输入循环
//做点什么
$y=$y+10;//您需要将加法运算分配给一个变量。现在y被添加到10,结果被分配给y。请注意,$y++相当于$y=$y+1
}

您必须将值重新分配给变量。
++
是一个特殊运算符,与
$y=$y+1
相同。
$y = $y + 10;
// commenting the code with description
$x = 630; // initialize x
$y = 10;  // initialize y

while ($y < $x){ // checking whether x is greater than y or not. if it is greater enter loop
// do something
$y = $y+10; // you need to assign the addition operation to a variable. now y is added to 10 and the result is assigned to y. please note that $y++ is equivalent to $y = $y + 1
}