Print_r (PHP 4, PHP 5) Print_r-Print easy-to-understand information about variables. description boolPrint_r(mixed expression [, bool return])
Note: The parameters return are added in PHP 4.3.0.
Print_r () displays easy-to-understand information about a variable. If a string,integer , or floatis given, the variable value itself is printed. If an arrayis given, the keys and elements are displayed in a certain format. object is similar to an array. Remember thatprint_r () moves the pointer of the array to the last edge. Use Reset () to get the pointer back to the beginning.
<pre> <?php $a= Array (' A '=' Apple ', ' B '=' Banana ', ' C '= = Array (' x ',' y ',' Z ')); Print_r($a); ?> </pre> |
The above code will output:
<pre>array ( [A] = Apple [b] = Banana [c] = = Array ( [0] = x [1] = y [2] = Z )) </pre> |
If you want to capture the output of Print_r () , you can use return parameters. If this parameter is set to TRUE,print_r () will not print the result (this is the default action), but instead return its output.
Example 1. returnparameter Examples
<?php $b= Array (' m '=' Monkey ', ' foo '=' Bar ', ' x '= = Array (' x ', ' y ', ' Z ')); $results= Print_r($b, true); //$results contains the output of the Print_r ?> |
|
Note: If you want to capture the output of Print_r () in a version prior to PHP 4.3.0, you can use the output control function.
|