当我执行这段代码时:
$result = mysql_query("SELECT * FROM example_table");
$i = 0;
while ($row = mysql_fetch_array($result))
{
for ($j = 0; $j < $c; $j++)
{
if ($db_array[$j]['ID'] == $row['id'])
{
$del_counter = 0;
break 2;
}
else
$del_counter = 1;
}
if ($del_counter == 1)
{
$del_array[$i] = $row['id'];
$i++;
}
}这不会中断两级循环。相反,$del_array存储所有行ids。我需要将行与数组“db_array”(从数据库获取)进行比较。并且需要检查从数据库中删除了db_array的哪些元素。因此,我所做的是尝试将已删除项目的in存储在一个数组中。但是休息并不起作用。我是不是遗漏了什么?
感谢大家的期待。
BG
发布于 2011-09-28 16:46:04
根据PHP手册:
1) break ends execution of the current for, foreach, while, do-while or switch structure
2) break accepts an optional numeric argument which tells it
how many (the above mentioned) nested enclosing structures are to be broken out of您的休息是在级别2,因此break 2;应该像预期的那样工作,所以问题在其他地方。是否执行了break 2?
在任何情况下,我都会推荐一个更健壮的解决方案,例如
$ok = True;
while (($row = mysql_fetch_array($result)) && $ok) {
...
if (...) $ok = False; // anywhere deep
...
if ($ok) {...}
}https://stackoverflow.com/questions/7580476
复制相似问题