print_r: Expanded example, reworded a bit, See also, and implemented the

former Warning as a Note. (<4.0.4 print_r($GLOBALS) is bad)


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@66625 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Philip Olson 2002-01-01 20:38:06 +00:00
parent b34dca461d
commit ceda18b1b0

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.88 $ -->
<!-- $Revision: 1.89 $ -->
<reference id="ref.variables">
<title>Variable Functions</title>
<titleabbrev>Variables</titleabbrev>
@ -898,9 +898,9 @@ print isset ($foo); // FALSE
</funcprototype>
</funcsynopsis>
<simpara>
This function displays information about the values of variables
in a way that's readable by humans. If given a <type>string</type>,
<type>integer</type> or <type>float</type>, the value itself will be
<function>print_r</function> displays information about a variable
in a way that's readable by humans. If given a <type>string</type>,
<type>integer</type> or <type>float</type>, the value itself will be
printed. If given an <type>array</type>,
values will be presented in a format that shows keys and
elements. Similar notation is used for <type>object</type>s.
@ -910,23 +910,56 @@ print isset ($foo); // FALSE
pointer to the end. Use <function>reset</function> to bring
it back to beginning.
</simpara>
&tip.ob-capture;
<simpara>
Compare <function>print_r</function> to
<function>var_dump</function>.
</simpara>
&tip.ob-capture;
<para>
<informalexample>
<programlisting role="php">
<![CDATA[
<pre>
<?php
$a = array (1, 2, array ("a", "b", "c"));
print_r ($a);
$a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x','y','z'));
print_r ($a);
?>
</pre>
]]>
</programlisting>
</informalexample>
</para>
<para>
Which will output:
<screen>
<![CDATA[
<pre>
Array
(
[a] => apple
[b] => banana
[c] => Array
(
[0] => x
[1] => y
[2] => z
)
)
</pre>
]]>
</screen>
</para>
<note>
<simpara>
Prior to PHP 4.0.4, <function>print_r</function> will continue forever
if given an <type>array</type> or <type>object</type> that
contains a direct or indirect reference to itself. An example
is <literal>print_r($GLOBALS)</literal> because
<literal>$GLOBALS</literal> is itself a global variable that
contains a reference to itself.
</simpara>
</note>
<simpara>
See also <function>ob_start</function>, <function>var_dump</function>,
and <function>var_export</function>.
</simpara>
</refsect1>
</refentry>