📄 function.func-get-args.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Returns an array comprising a function's argument list</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="function.func-get-arg.html">func_get_arg</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.func-num-args.html">func_num_args</a></div> <div class="up"><a href="ref.funchand.html">Function handling Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.func-get-args" class="refentry"> <div class="refnamediv"> <h1 class="refname">func_get_args</h1> <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">func_get_args</span> — <span class="dc-title">Returns an array comprising a function's argument list</span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">array</span> <span class="methodname"><b><b>func_get_args</b></b></span> ( <span class="methodparam">void</span> )</div> <p class="para rdfs-comment"> Gets an array of the function's argument list. </p> <p class="para"> This function may be used in conjunction with <a href="function.func-get-arg.html" class="function">func_get_arg()</a> and <a href="function.func-num-args.html" class="function">func_num_args()</a> to allow user-defined functions to accept variable-length argument lists. </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns an array in which each element is a copy of the corresponding member of the current user-defined function's argument list. </p> </div> <div class="refsect1 changelog"> <h3 class="title">ChangeLog</h3> <p class="para"> <table class="informaltable"> <colgroup> <thead valign="middle"> <tr valign="middle"> <th colspan="1">Version</th> <th colspan="1">Description</th> </tr> </thead> <tbody valign="middle" class="tbody"> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">5.3.0</td> <td colspan="1" rowspan="1" align="left"> This function can now be used in parameter lists. </td> </tr> </tbody> </colgroup> </table> </p> </div> <div class="refsect1 errors"> <h3 class="title">Errors/Exceptions</h3> <p class="para"> Generates a warning if called from outside of a user-defined function. </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 <b>func_get_args()</b> example</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">foo</span><span style="color: #007700">()<br />{<br /> </span><span style="color: #0000BB">$numargs </span><span style="color: #007700">= </span><span style="color: #0000BB">func_num_args</span><span style="color: #007700">();<br /> echo </span><span style="color: #DD0000">"Number of arguments: $numargs<br />\n"</span><span style="color: #007700">;<br /> if (</span><span style="color: #0000BB">$numargs </span><span style="color: #007700">>= </span><span style="color: #0000BB">2</span><span style="color: #007700">) {<br /> echo </span><span style="color: #DD0000">"Second argument is: " </span><span style="color: #007700">. </span><span style="color: #0000BB">func_get_arg</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">) . </span><span style="color: #DD0000">"<br />\n"</span><span style="color: #007700">;<br /> }<br /> </span><span style="color: #0000BB">$arg_list </span><span style="color: #007700">= </span><span style="color: #0000BB">func_get_args</span><span style="color: #007700">();<br /> for (</span><span style="color: #0000BB">$i </span><span style="color: #007700">= </span><span style="color: #0000BB">0</span><span style="color: #007700">; </span><span style="color: #0000BB">$i </span><span style="color: #007700">< </span><span style="color: #0000BB">$numargs</span><span style="color: #007700">; </span><span style="color: #0000BB">$i</span><span style="color: #007700">++) {<br /> echo </span><span style="color: #DD0000">"Argument $i is: " </span><span style="color: #007700">. </span><span style="color: #0000BB">$arg_list</span><span style="color: #007700">[</span><span style="color: #0000BB">$i</span><span style="color: #007700">] . </span><span style="color: #DD0000">"<br />\n"</span><span style="color: #007700">;<br /> }<br />}<br /><br /></span><span style="color: #0000BB">foo</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">2</span><span style="color: #007700">, </span><span style="color: #0000BB">3</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> </div> <div class="refsect1 notes"> <h3 class="title">Notes</h3> <blockquote><p><b class="note">Note</b>: Because this function depends on thecurrent scope to determine parameter details, it cannot be used as afunction parameter. If this value must be passed, the results should be assignedto a variable, and that variable should be passed.<br /></p></blockquote> <blockquote><p><b class="note">Note</b>: <span class="simpara"> This function returns a copy of the passed arguments only, and does not account for default (non-passed) arguments. </span> </p></blockquote> </div> <div class="refsect1 seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><a href="function.func-get-arg.html" class="function" rel="rdfs-seeAlso">func_get_arg()</a></li> <li class="member"><a href="function.func-num-args.html" class="function" rel="rdfs-seeAlso">func_num_args()</a></li> </ul> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.func-get-arg.html">func_get_arg</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.func-num-args.html">func_num_args</a></div> <div class="up"><a href="ref.funchand.html">Function handling Functions</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 + -