The difference between three output statements of 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 ('a' => 'apple', 'b' => 'banana', 'c' => array ('x','y','z')); print_r ($a); ?> <?php $a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x','y','z')); $results = print_r ($a, true);//$results 包含了 print_r 的输出结果 print_r ($results); ?>
The results of the above two methods are:
Array ( [a] => apple [b] => banana [c] => Array ( [0] => x [1] => y [2] => z ) )
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!