Sophie

Sophie

distrib > Mageia > 4 > i586 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 5421

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Prints human-readable information about a variable</title>

 </head>
 <body><div class="manualnavbar" 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> &mdash; <span class="dc-title">
   Prints human-readable information about a variable
  </span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.print-r-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"><strong>print_r</strong></span>
    ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$expression</code></span>
   [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$return</code><span class="initializer"> = false</span></span>
  ] )</div>

  <p class="para rdfs-comment">
    <span class="function"><strong>print_r()</strong></span> displays information about a variable
   in a way that&#039;s readable by humans.  
  </p>
  <p class="para">
    <span class="function"><strong>print_r()</strong></span>,  <span class="function"><a href="function.var-dump.html" class="function">var_dump()</a></span> and
    <span class="function"><a href="function.var-export.html" class="function">var_export()</a></span> will
   also show protected and private properties of objects with PHP 5.
   Static class members will not be shown.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.print-r-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>

    <dt>

     <span class="term"><em><code class="parameter">expression</code></em></span>
     <dd>

      <p class="para">
       The expression to be printed.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">return</code></em></span>
     <dd>

      <p class="para">
       If you would like to capture the output of  <span class="function"><strong>print_r()</strong></span>, 
       use the <em><code class="parameter">return</code></em> parameter.  When this parameter is set
       to <strong><code>TRUE</code></strong>,  <span class="function"><strong>print_r()</strong></span> will return the information rather than print it.
      </p>
     </dd>

    </dt>

   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.print-r-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   If given a <span class="type"><a href="language.types.string.html" class="type string">string</a></span>, <span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span> or <span class="type"><a href="language.types.float.html" class="type float">float</a></span>,
   the value itself will be printed.  If given an <span class="type"><a href="language.types.array.html" class="type array">array</a></span>, values
   will be presented in a format that shows keys and elements.  Similar
   notation is used for <span class="type"><a href="language.types.object.html" class="type object">object</a></span>s.
  </p>
  <p class="para">
   When the <em><code class="parameter">return</code></em> parameter is <strong><code>TRUE</code></strong>, this function
   will return a <span class="type"><a href="language.types.string.html" class="type string">string</a></span>. Otherwise, the return value is <strong><code>TRUE</code></strong>.
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.print-r-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para">When the <em><code class="parameter">return</code></em> parameter
is used, this function uses internal output buffering so it cannot be used inside an
 <span class="function"><a href="function.ob-start.html" class="function">ob_start()</a></span> callback function.</p></p></blockquote>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.print-r-changelog">
  <h3 class="title">Changelog</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>4.3.0</td>
       <td>
        The <em><code class="parameter">return</code></em> parameter was added. If you need to
        capture the output of  <span class="function"><strong>print_r()</strong></span> with an older 
        version of PHP prior, use the 
        <a href="ref.outcontrol.html" class="link">output-control functions</a>.
       </td>
      </tr>

      <tr>
       <td>4.0.4</td>
       <td>
        Prior to PHP 4.0.4,  <span class="function"><strong>print_r()</strong></span> will continue forever
        if given an <span class="type"><a href="language.types.array.html" class="type array">array</a></span> or <span class="type"><a href="language.types.object.html" class="type object">object</a></span> that
        contains a direct or indirect reference to itself.  An example
        is <em>print_r($GLOBALS)</em> because
        <em>$GLOBALS</em> is itself a global variable that
        contains a reference to itself.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.print-r-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-5269">
    <p><strong>Example #1  <span class="function"><strong>print_r()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
&lt;pre&gt;<br /><span style="color: #0000BB">&lt;?php<br />$a&nbsp;</span><span style="color: #007700">=&nbsp;array&nbsp;(</span><span style="color: #DD0000">'a'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'apple'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'b'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'banana'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'c'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;array&nbsp;(</span><span style="color: #DD0000">'x'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'y'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'z'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">print_r&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">$a</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;<br /></span>&lt;/pre&gt;</span>
</code></div>
    </div>

    <div class="example-contents"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
&lt;pre&gt;
Array
(
    [a] =&gt; apple
    [b] =&gt; banana
    [c] =&gt; Array
        (
            [0] =&gt; x
            [1] =&gt; y
            [2] =&gt; z
        )
)
&lt;/pre&gt;
</pre></div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-5270">
    <p><strong>Example #2 <em><code class="parameter">return</code></em> parameter example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$b&nbsp;</span><span style="color: #007700">=&nbsp;array&nbsp;(</span><span style="color: #DD0000">'m'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'monkey'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'foo'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'bar'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'x'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;array&nbsp;(</span><span style="color: #DD0000">'x'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'y'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'z'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$results&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$b</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;$results&nbsp;now&nbsp;contains&nbsp;output&nbsp;from&nbsp;print_r<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.print-r-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"> <span class="function"><a href="function.ob-start.html" class="function" rel="rdfs-seeAlso">ob_start()</a> - Turn on output buffering</span></li>
    <li class="member"> <span class="function"><a href="function.var-dump.html" class="function" rel="rdfs-seeAlso">var_dump()</a> - Dumps information about a variable</span></li>
    <li class="member"> <span class="function"><a href="function.var-export.html" class="function" rel="rdfs-seeAlso">var_export()</a> - Outputs or returns a parsable string representation of a variable</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" 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>