<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >print_r</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="Manual do PHP" HREF="index.html"><LINK REL="UP" TITLE="Variáveis, Funções" HREF="ref.variables.html"><LINK REL="PREVIOUS" TITLE="isset" HREF="function.isset.html"><LINK REL="NEXT" TITLE="serialize" HREF="function.serialize.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Manual do PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.isset.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.serialize.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.print-r" ></A >print_r</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN230310" ></A ><P > (PHP 4, PHP 5)</P >print_r -- Prints human-readable information about a variable </DIV ><DIV CLASS="refsect1" ><A NAME="AEN230313" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >print_r</B > ( mixed expression [, bool return] )<BR ></BR ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Nota: </B > The <CODE CLASS="parameter" >return</CODE > parameter was added in PHP 4.3.0 </P ></BLOCKQUOTE ></DIV ><P > <B CLASS="function" >print_r()</B > displays information about a variable in a way that's readable by humans. If given a <A HREF="language.types.string.html" ><B CLASS="type" >string</B ></A >, <A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A > or <A HREF="language.types.float.html" ><B CLASS="type" >float</B ></A >, the value itself will be printed. If given an <A HREF="language.types.array.html" ><B CLASS="type" >array</B ></A >, values will be presented in a format that shows keys and elements. Similar notation is used for <A HREF="language.types.object.html" ><B CLASS="type" >object</B ></A >s. <B CLASS="function" >print_r()</B >, <A HREF="function.var-dump.html" ><B CLASS="function" >var_dump()</B ></A > and <A HREF="function.var-export.html" ><B CLASS="function" >var_export()</B ></A > will also show protected and private properties of objects with PHP 5. </P ><P > Remember that <B CLASS="function" >print_r()</B > will move the array pointer to the end. Use <A HREF="function.reset.html" ><B CLASS="function" >reset()</B ></A > to bring it back to beginning. </P ><P > <DIV CLASS="informalexample" ><P ></P ><A NAME="AEN230341" ></A ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <pre><br /><font color="#0000BB"><?php<br /> $a </font><font color="#007700">= array (</font><font color="#DD0000">'a' </font><font color="#007700">=> </font><font color="#DD0000">'apple'</font><font color="#007700">, </font><font color="#DD0000">'b' </font><font color="#007700">=> </font><font color="#DD0000">'banana'</font><font color="#007700">, </font><font color="#DD0000">'c' </font><font color="#007700">=> array (</font><font color="#DD0000">'x'</font><font color="#007700">, </font><font color="#DD0000">'y'</font><font color="#007700">, </font><font color="#DD0000">'z'</font><font color="#007700">));<br /> </font><font color="#0000BB">print_r </font><font color="#007700">(</font><font color="#0000BB">$a</font><font color="#007700">);<br /></font><font color="#0000BB">?><br /></font></pre></font> </code></TD ></TR ></TABLE ><P >O exemplo acima irá imprimir:</P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" ><pre> Array ( [a] => apple [b] => banana [c] => Array ( [0] => x [1] => y [2] => z ) ) </pre></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P > If you would like to capture the output of <B CLASS="function" >print_r()</B >, use the <CODE CLASS="parameter" >return</CODE > parameter. If this parameter is set to <TT CLASS="constant" ><B >TRUE</B ></TT >, <B CLASS="function" >print_r()</B > will return its output, instead of printing it (which it does by default). </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Nota: </B >Esta função usa internemente o buffer de saída com este parãmetro, assim não pode ser usada dentro da função de callback <A HREF="function.ob-start.html" ><B CLASS="function" >ob_start()</B ></A >.</P ></BLOCKQUOTE ></DIV ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN230354" ></A ><P ><B >Exemplo 1. <CODE CLASS="parameter" >return</CODE > parameter example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /> $b </font><font color="#007700">= array (</font><font color="#DD0000">'m' </font><font color="#007700">=> </font><font color="#DD0000">'monkey'</font><font color="#007700">, </font><font color="#DD0000">'foo' </font><font color="#007700">=> </font><font color="#DD0000">'bar'</font><font color="#007700">, </font><font color="#DD0000">'x' </font><font color="#007700">=> array (</font><font color="#DD0000">'x'</font><font color="#007700">, </font><font color="#DD0000">'y'</font><font color="#007700">, </font><font color="#DD0000">'z'</font><font color="#007700">));<br /> </font><font color="#0000BB">$results </font><font color="#007700">= </font><font color="#0000BB">print_r</font><font color="#007700">(</font><font color="#0000BB">$b</font><font color="#007700">, </font><font color="#0000BB">true</font><font color="#007700">); </font><font color="#FF8000">//$results now contains output from print_r<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Nota: </B > If you need to capture the output of <B CLASS="function" >print_r()</B > with a version of PHP prior to 4.3.0, use the <A HREF="ref.outcontrol.html" > output-control functions</A >. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Nota: </B > Prior to PHP 4.0.4, <B CLASS="function" >print_r()</B > will continue forever if given an <A HREF="language.types.array.html" ><B CLASS="type" >array</B ></A > or <A HREF="language.types.object.html" ><B CLASS="type" >object</B ></A > that contains a direct or indirect reference to itself. An example is <TT CLASS="literal" >print_r($GLOBALS)</TT > because <TT CLASS="literal" >$GLOBALS</TT > is itself a global variable that contains a reference to itself. </P ></BLOCKQUOTE ></DIV ><P > See also <A HREF="function.ob-start.html" ><B CLASS="function" >ob_start()</B ></A >, <A HREF="function.var-dump.html" ><B CLASS="function" >var_dump()</B ></A > and <A HREF="function.var-export.html" ><B CLASS="function" >var_export()</B ></A >. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.isset.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Principal</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.serialize.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >isset</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.variables.html" ACCESSKEY="U" >Acima</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >serialize</TD ></TR ></TABLE ></DIV ></BODY ></HTML >