【发布时间】:2023-03-09 02:10:01
【问题描述】:
我在 if else 语句中返回了一些东西。它是结束整个功能还是仅结束 ifelse 范围?
function user () {
if (//first) {
return TRUE;
}
//somecode
if (//second) {
return FALSE;
}
return TRUE;
}
在上面的代码中,如果我的第一个条件为真,它是结束整个函数还是只结束第一个 ifelse 范围?
【问题讨论】:
-
你自己试试看吧?
-
来自PHP Docs:
If called from within a function, the return statement immediately ends execution of the current function, and returns its argument as the value of the function call..... 在询问 StackOverflow 之前阅读 PHP 文档真的很有用,可以节省您和我们的时间 -
在您发表评论后,我将自己尝试这些愚蠢的问题。谢谢你! :) 顺便说一句,我试过这个,但我更困惑。
-
@MarkBaker 我总是首先阅读 PHP 文档。但我就是无法摆脱这种困惑。
-
我建议你阅读 return and continue 和 break and exit and die 这些基础知识
标签: php function if-statement scope return