我正在运行一个在计数器上打勾的循环。
基本上,它是
<counter>
<a php form>计数器正在从数据库中提取对象。如果有10个或更多的对象被拉出,我希望关闭窗体。但是,我不确定如何从“while”语句中取出计数器?
<?php
$counter = 0;
//LOOPING CODE IS HERE
example: ---- 'while ( $var->this() ) : $var->that();'----------
// Add to counter
$counter = ++$counter;
// Cleanup after ourselves
endwhile;
?>现在,在endwhile;之后,我需要能够调用$counter的最后一个值,并确定它是=还是> 10?
发布于 2012-08-21 08:12:54
语法是
$counter = 0;
while(condition is true)
{
//increment $counter
if($counter >= 10)
break; //break out of the loop
}
print($counter);发布于 2012-08-21 08:12:11
当计数器超过10时,您可以中断while循环,然后您仍有$counter可用。
<?php
$counter = 0;
while ($var->this() && $counter < 10) {
$var->that();
$counter++;
}
echo $counter;
?>https://stackoverflow.com/questions/12046871
复制相似问题