about.prototypes.html
来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 183 行
HTML
183 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>How to read a function definition (prototype)</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="about.notes.html">About user notes</a></div> <div class="next" style="text-align: right; float: right;"><a href="about.phpversions.html">PHP versions documented in this manual</a></div> <div class="up"><a href="about.html">About the manual</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="about.prototypes" class="sect1"> <h2 class="title">How to read a function definition (prototype)</h2> <p class="para"> Each function in the manual is documented for quick reference. Knowing how to read and understand the text will make learning PHP much easier. Rather than relying on examples or cut/paste, everyone should know how to read function definitions (prototypes). Let's begin: </p> <blockquote><p><b class="note">Note</b>: <b> Prerequisite: Basic understanding of <a href="language.types.html" class="link">types</a> </b><br /> Although PHP is a loosely typed language, it's important to have a basic understanding of <a href="language.types.html" class="link">types</a> as they have important meaning. <br /> </p></blockquote> <p class="para"> Function definitions tell us what type of value is <a href="functions.returning-values.html" class="link">returned</a>. Let's use the definition for <a href="function.strlen.html" class="function">strlen()</a> as our first example: </p> <p class="para"> <div class="example-contents"><pre><div class="cdata"><pre>strlen(PHP 4, PHP 5)strlen -- Get string lengthDescriptionint strlen ( string $string )Returns the length of given string.</pre></div> </pre></div> </p> <p class="para"> <table border="5"> <caption><b>Explanation of a function definition</b></caption> <colgroup> <thead valign="middle"> <tr valign="middle"> <th colspan="1">Part</th> <th colspan="1">Description</th> </tr> </thead> <tbody valign="middle" class="tbody"> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"> strlen </td> <td colspan="1" rowspan="1" align="left"> The function name. </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"> (PHP 4, PHP 5, PHP 6) </td> <td colspan="1" rowspan="1" align="left"> strlen() has been around in all versions of PHP 4, PHP 5 and PHP 6 </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"> int </td> <td colspan="1" rowspan="1" align="left"> Type of value this function returns, which is an <a href="language.types.integer.html" class="type integer">integer</a> (i.e. the length of a string is measured in numbers). </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"> ( string $string ) </td> <td colspan="1" rowspan="1" align="left"> The first (and in this case the only) parameter/argument for this function is named <i><tt class="parameter">string</tt></i>, and it's a <a href="language.types.string.html" class="type string">string</a>. </td> </tr> </tbody> </colgroup> </table> </p> <p class="para"> We could rewrite the above function definition in a generic way: </p> <p class="para"> <div class="example-contents"><pre><div class="cdata"><pre> returned type function name ( parameter type parameter name )</pre></div> </pre></div> </p> <p class="para"> Many functions take on multiple parameters, such as <a href="function.in-array.html" class="function">in_array()</a>. Its prototype is as follows: </p> <p class="para"> <div class="example-contents"><pre> <div class="cdata"><pre> bool in_array ( mixed $needle, array $haystack [, bool $strict])</pre></div> </pre></div> </p> <p class="para"> What does this mean? in_array() returns a <a href="language.types.boolean.html" class="link">boolean</a> value, <b><tt>TRUE</tt></b> on success (if the <i><tt class="parameter">needle</tt></i> was found in the <i><tt class="parameter">haystack</tt></i>) or <b><tt>FALSE</tt></b> on failure (if the <i><tt class="parameter">needle</tt></i> was not found in the <i><tt class="parameter">haystack</tt></i>). The first parameter is named <i><tt class="parameter">needle</tt></i> and it can be of many different <a href="language.types.html" class="link">types</a>, so we call it "<em class="emphasis">mixed</em>". This mixed <i><tt class="parameter">needle</tt></i> (what we're looking for) can be either a scalar value (string, integer, or <a href="language.types.float.html" class="link">float</a>), or an <a href="language.types.array.html" class="link">array</a>. <i><tt class="parameter">haystack</tt></i> (the array we're searching in) is the second parameter. The third <em class="emphasis">optional</em> parameter is named <i><tt class="parameter">strict</tt></i>. All optional parameters are seen in <em class="emphasis">[</em> brackets <em class="emphasis">]</em>. The manual states that the <i><tt class="parameter">strict</tt></i> parameter defaults to boolean <b><tt>FALSE</tt></b>. See the manual page on each function for details on how they work. </p> <p class="para"> There are also functions with more complex PHP version information. Take <a href="function.html-entity-decode.html" class="function">html_entity_decode()</a> as an example: </p> <p class="para"> <div class="example-contents"><pre> <div class="cdata"><pre>(PHP 4 >= 4.3.0, PHP 5)</pre></div> </pre></div> </p> <p class="para"> This means that this function has only been available in a released version since PHP 4.3.0. </p> </div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="about.notes.html">About user notes</a></div> <div class="next" style="text-align: right; float: right;"><a href="about.phpversions.html">PHP versions documented in this manual</a></div> <div class="up"><a href="about.html">About the manual</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?