2 回答

TA贡献1827条经验 获得超8个赞
您不能直接从函数内部中断外循环,但可以返回一个值来告知外循环中断:
function foo($is_bas)
{
if ($is_bas == 'BAS') {
echo 'here';
return true;
}
return false;
}
function bar()
{
$is_baz = 'BAZ';
$is_bas = 'BAS';
while (TRUE) {
echo 'Im';
if ($is_baz == 'BAZ') {
if (foo($is_bas)) break;
}
echo '!!!';
break;
}
echo 'too';
}
bar();
输出:
Imheretoo

TA贡献1807条经验 获得超9个赞
function foo($is_bas)
{
if ($is_bas == 'BAS') {
echo 'here';
return true;
}
echo 'not here';
return false;
}
function bar()
{
$is_baz = 'BAZ';
$is_bas = 'BAS';
while (TRUE) {
echo 'Im';
if ($is_baz == 'BAZ' && foo($is_bas)) {
break;
}
echo '!!!';
break;
}
echo 'too';
}
bar();
- 2 回答
- 0 关注
- 141 浏览
添加回答
举报