【发布时间】:2011-05-15 06:45:28
【问题描述】:
如果不满足某些条件,我会尝试跳到循环的下一次迭代。问题是循环仍在继续。
我哪里出错了?
根据第一条评论更新了代码示例。
foreach ($this->routes as $route => $path) {
$continue = 0;
...
// Continue if route and segment count do not match.
if (count($route_segments) != $count) {
$continue = 12;
continue;
}
// Continue if no segment match is found.
for($i=0; $i < $count; $i++) {
if ($route_segments[$i] != $segments[$i] && ! preg_match('/^\x24[0-9]+$/', $route_segments[$i])) {
$continue = 34;
continue;
}
}
echo $continue; die(); // Prints out 34
【问题讨论】:
-
您正在覆盖
$continue。完全有可能输入它设置为 1,然后在循环迭代中设置为 2。 -
在
foreach之后设置$continue = 0;... 我敢打赌你不会再得到1。 A for 2,您需要告诉它继续向上 2 级,所以continue 2;,否则它将进入for循环的下一次迭代...