📄 function.return.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>return</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="control-structures.declare.html">declare</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.require.html">require</a></div> <div class="up"><a href="language.control-structures.html">Control Structures</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.return" class="sect1"> <h2 class="title">return</h2> <p class="simpara"> If called from within a function, the <b>return()</b> statement immediately ends execution of the current function, and returns its argument as the value of the function call. <b>return()</b> will also end the execution of an <a href="function.eval.html" class="function">eval()</a> statement or script file. </p> <p class="simpara"> If called from the global scope, then execution of the current script file is ended. If the current script file was <b>include()</b>ed or <b>require()</b>ed, then control is passed back to the calling file. Furthermore, if the current script file was <b>include()</b>ed, then the value given to <b>return()</b> will be returned as the value of the <b>include()</b> call. If <b>return()</b> is called from within the main script file, then script execution ends. If the current script file was named by the <a href="ini.core.html#ini.auto-prepend-file" class="link">auto_prepend_file</a> or <a href="ini.core.html#ini.auto-append-file" class="link">auto_append_file</a> configuration options in <var class="filename">php.ini</var>, then that script file's execution is ended. </p> <p class="simpara">For more information, see <a href="functions.returning-values.html" class="link">Returning values</a>. </p> <p class="para"> <blockquote><p><b class="note">Note</b>: <span class="simpara"> Note that since <b>return()</b> is a language construct and not a function, the parentheses surrounding its arguments are not required. It is common to leave them out, and you actually should do so as PHP has less work to do in this case. </span> </p></blockquote> <blockquote><p><b class="note">Note</b>: <span class="simpara"> You should <em class="emphasis">never</em> use parentheses around your return variable when returning by reference, as this will not work. You can only return variables by reference, not the result of a statement. If you use <i>return ($a);</i> then you're not returning a variable, but the result of the expression <i>($a)</i> (which is, of course, the value of <var class="varname">$a</var>). </span> </p></blockquote> </p> </div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="control-structures.declare.html">declare</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.require.html">require</a></div> <div class="up"><a href="language.control-structures.html">Control Structures</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -