PHP---Print_r

Source: Internet
Author: User

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.


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< C12/>[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.

PHP---Print_r

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.