gpt4 book ai didi

php - 如何打破嵌套函数的循环?

转载 作者:行者123 更新时间:2023-12-02 21:18:00 26 4
gpt4 key购买 nike

问题来了

public function loop (){
while($this->controlFunction()){
//do stuff
}
}
public function controlFunction (){
$this->nestedFunction();
}

public function nestedFunction (){
if($condA){ //whatsoever the condition
break;
}
}

这可能吗?我不想返回然后使用标志再次返回,看起来像意大利面条代码

谢谢大家的回答,经过深思熟虑,我的问题似乎很愚蠢......无论如何,谢谢你:)

最佳答案

根据the documentation :

break ends execution of the current for, foreach, while, do-while or switch structure

由于调用函数会更改作用域,因此 break 语句对执行 while 循环的前一个作用域没有影响。

事实上,由于作用域与 nestedFunction 方法不同,调用 break 将导致 fatal error (E_ERROR),因为该作用域不知道前一个作用域中运行的 while 循环。

Fatal error: Cannot break/continue 1 level

所以不,这是不可能的。

关于php - 如何打破嵌套函数的循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29355923/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com