是否可以在 php 中重置 foreach?
例如:
foreach($rows as $row)
{
if(something true)
{
continue foreach;
}
else
{
break;
reset foreach;//I mean start foreach again...
}
}
--------------------------------编辑
谢谢我 friend 的回答...
条件从 foreach 的结果生成,所以我不能使用函数。 我想按(来回示例)字母表对它进行排序...在许多 DIV html 中。 对于相同的原因,我无法通过 SQL 过滤结果。
所以我想我必须使用 css 技巧。
最佳答案
您可以围绕这些行做一些事情(并避免递归的限制):
while (True) {
$reset = False;
foreach ($rows as $row) {
if(something true) {
continue;
} else {
$reset = True;
break;
}
}
if ( ! $reset ) {
break; # break out of the while(true)
}
# otherwise the foreach loop is `reset`
}
关于php - 如何在PHP中强制重置foreach,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22150303/