function.print-r.html
来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 220 行
HTML
220 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Prints human-readable information about a variable</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.isset.html">isset</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.serialize.html">serialize</a></div> <div class="up"><a href="ref.var.html">Variable handling Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.print-r" class="refentry"> <div class="refnamediv"> <h1 class="refname">print_r</h1> <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">print_r</span> — <span class="dc-title"> Prints human-readable information about a variable </span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><b><b>print_r</b></b></span> ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <tt class="parameter">$expression</tt></span> [, <span class="methodparam"><span class="type">bool</span> <tt class="parameter">$return</tt></span> ] )</div> <p class="para rdfs-comment"> <b>print_r()</b> displays information about a variable in a way that's readable by humans. </p> <p class="para"> <b>print_r()</b>, <a href="function.var-dump.html" class="function">var_dump()</a> and <a href="function.var-export.html" class="function">var_export()</a> will also show protected and private properties of objects with PHP 5. Static class members will not be shown. </p> <p class="para"> Remember that <b>print_r()</b> will move the array pointer to the end. Use <a href="function.reset.html" class="function">reset()</a> to bring it back to beginning. </p> </div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><i><tt class="parameter">expression</tt></i></span> <dd> <p class="para"> The expression to be printed. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">return</tt></i></span> <dd> <p class="para"> If you would like to capture the output of <b>print_r()</b>, use the <i><tt class="parameter">return</tt></i> parameter. If this parameter is set to <b><tt>TRUE</tt></b>, <b>print_r()</b> will return its output, instead of printing it (which it does by default). </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> If given a <a href="language.types.string.html" class="type string">string</a>, <a href="language.types.integer.html" class="type integer">integer</a> or <a href="language.types.float.html" class="type float">float</a>, the value itself will be printed. If given an <a href="language.types.array.html" class="type array">array</a>, values will be presented in a format that shows keys and elements. Similar notation is used for <a href="language.types.object.html" class="type object">object</a>s. </p> </div> <div class="refsect1 notes"> <h3 class="title">Notes</h3> <blockquote><p><b class="note">Note</b>: This function uses internal output bufferingwith this parameter so it can not be used inside an<a href="function.ob-start.html" class="function">ob_start()</a> callback function.<br /></p></blockquote> </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">4.3.0</td> <td colspan="1" rowspan="1" align="left"> The <i><tt class="parameter">return</tt></i> parameter was added. If you need to capture the output of <b>print_r()</b> with an older version of PHP prior, use the <a href="ref.outcontrol.html" class="link">output-control functions</a>. </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">4.0.4</td> <td colspan="1" rowspan="1" align="left"> Prior to PHP 4.0.4, <b>print_r()</b> will continue forever if given an <a href="language.types.array.html" class="type array">array</a> or <a href="language.types.object.html" class="type object">object</a> that contains a direct or indirect reference to itself. An example is <i>print_r($GLOBALS)</i> because <i>$GLOBALS</i> is itself a global variable that contains a reference to itself. </td> </tr> </tbody> </colgroup> </table> </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 <b>print_r()</b> example</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><pre><br /><span style="color: #0000BB"><?php<br />$a </span><span style="color: #007700">= array (</span><span style="color: #DD0000">'a' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'apple'</span><span style="color: #007700">, </span><span style="color: #DD0000">'b' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'banana'</span><span style="color: #007700">, </span><span style="color: #DD0000">'c' </span><span style="color: #007700">=> array (</span><span style="color: #DD0000">'x'</span><span style="color: #007700">, </span><span style="color: #DD0000">'y'</span><span style="color: #007700">, </span><span style="color: #DD0000">'z'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">print_r </span><span style="color: #007700">(</span><span style="color: #0000BB">$a</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?><br /></span></pre></span></code></div> </div> <div class="example-contents"><p>The above example will output:</p></div> <div class="example-contents"><pre><div class="cdata"><pre><pre>Array( [a] => apple [b] => banana [c] => Array ( [0] => x [1] => y [2] => z ))</pre></pre></div> </pre></div> </div> </p> <p class="para"> <div class="example"> <p><b>Example #2 <i><tt class="parameter">return</tt></i> parameter example</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br />$b </span><span style="color: #007700">= array (</span><span style="color: #DD0000">'m' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'monkey'</span><span style="color: #007700">, </span><span style="color: #DD0000">'foo' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'bar'</span><span style="color: #007700">, </span><span style="color: #DD0000">'x' </span><span style="color: #007700">=> array (</span><span style="color: #DD0000">'x'</span><span style="color: #007700">, </span><span style="color: #DD0000">'y'</span><span style="color: #007700">, </span><span style="color: #DD0000">'z'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$results </span><span style="color: #007700">= </span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$b</span><span style="color: #007700">, </span><span style="color: #0000BB">true</span><span style="color: #007700">); </span><span style="color: #FF8000">// $results now contains output from print_r<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> </div> <div class="refsect1 seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><a href="function.ob-start.html" class="function" rel="rdfs-seeAlso">ob_start()</a></li> <li class="member"><a href="function.var-dump.html" class="function" rel="rdfs-seeAlso">var_dump()</a></li> <li class="member"><a href="function.var-export.html" class="function" rel="rdfs-seeAlso">var_export()</a></li> </ul> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.isset.html">isset</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.serialize.html">serialize</a></div> <div class="up"><a href="ref.var.html">Variable handling Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?