Home > Backend Development > PHP Problem > The difference between three kinds of output statements in php

The difference between three kinds of output statements in php

(*-*)浩
Release: 2023-02-24 12:14:02
Original
3656 people have browsed it

The difference between three output statements of php

The difference between three kinds of output statements in php

(1) echo is a PHP statement with no return value and is used to output an or Multiple strings

(2) print() is a function that can have a return value and can only print out the values ​​of simple type variables, such as int, string

(3) print_r() is a function that can have a return value and can print the value of complex type variables, such as arrays and objects

print_r detailed explanation: (Recommended learning: PHP programming from entry to proficiency)

bool print_r (mixed expression [, bool return])

The parameter return is in PHP 4.3.0 Added

If you want to capture the output of print_r(), you can use the return parameter. If this parameter is set to TRUE, print_r() will not print the results (this is the default action), but will return its output.

eg.

<?php
    $a = array (&#39;a&#39; => &#39;apple&#39;, &#39;b&#39; => &#39;banana&#39;, &#39;c&#39; => array (&#39;x&#39;,&#39;y&#39;,&#39;z&#39;));
    print_r ($a);
?>
<?php
    $a = array (&#39;a&#39; => &#39;apple&#39;, &#39;b&#39; => &#39;banana&#39;, &#39;c&#39; => array (&#39;x&#39;,&#39;y&#39;,&#39;z&#39;));
    $results = print_r ($a, true);//$results 包含了 print_r 的输出结果
    print_r ($results);
?>
Copy after login

The results of the above two methods are:

Array
(
    [a] => apple
    [b] => banana
    [c] => Array
        (
            [0] => x
            [1] => y
            [2] => z
        )
)
Copy after login

The above is the detailed content of The difference between three kinds of output statements in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template