【发布时间】:2013-08-10 19:53:08
【问题描述】:
如何在for loop 支票中添加or?
例如:
for ($i=1; ($i <= $untilPoint) or ($i <= $points); $i++){
.. code ...
}
【问题讨论】:
-
如果它不起作用(是吗?),那么你可以把它变成一个
do/while循环。
如何在for loop 支票中添加or?
例如:
for ($i=1; ($i <= $untilPoint) or ($i <= $points); $i++){
.. code ...
}
【问题讨论】:
do/while 循环。
您输入的正是有效的 PHP。比如这个程序:
<?
$untilPoint = 3;
$points = 5;
for ($i=1; ($i <= $untilPoint) or ($i <= $points); $i++){
echo("$i\n");
}
?>
打印这个:
1
2
3
4
5
(在 PHP 5.2.17 中测试,从 Bash 提示符运行)。
也就是说,我想知道您是否真的需要and 而不是or?如果$i 是点数组的索引,其中$points 是点数,$untilPoint 是任意截止值,那么您需要and,而不是or。
【讨论】:
应该是这样的,可能运行得稍微快一些。 您可以用 分隔,更多信息请参阅http://php.net/manual/en/control-structures.for.php
<?
$untilPoint = 3;
$points = 5;
for ($i=1; $i <= $untilPoint, $i <= $points; $i++){
echo($i , "\n");
}
?>
【讨论】: