我需要帮助。
我需要的是,当循环时,它将计算达到零后有多少循环。
$variable=50;//this is not fixed
$loop=0;
//------------------//
$variable-10;
//the $variable becomes 40
//$loop becomes 1
//repeat the process
$variable-10;
//the $variable becomes 30
//$loop becomes 2
//until the variable reaches zero then
//$loop becomes 5发布于 2013-01-09 10:10:15
$variable = 50;
$loop = 0;
while($variable > 0)
{
$variable -= 10;
$loop++;
}发布于 2013-01-09 10:10:54
在循环中实现变量$variable=50
$count=0;
for ($variable=50; $variable<=0; $variable-=10){
$count++;
}发布于 2013-01-09 10:22:22
代号高尔夫!
for($v=50,$c=0;($v-=10)>0;++$c);
echo $c;在这个非常简短的脚本的末尾,$c将表示循环的代码部分被执行的次数。本质上,它还表示执行递增序列的次数。
这与执行循环的测试的次数形成对比,由于exeting之前的最后一种情况,该次数固有地高出1。
https://stackoverflow.com/questions/14227215
复制相似问题