Differences between echo, print, and print_r in php: information can be output, but each of them has its own characteristics: & nbsp; number of type output variables output variable type return & #20540; the speed echo language structure is one or more simple type variables. for example, int and string do not have the fastest print language structure. a simple type variable, such as echo, print, and print_r differences in I php
Overview:
All three of them can output information, but each has its own characteristics:
| |
Type |
Number of output variables |
Output variable type |
Return value |
Speed |
| Echo |
Language structure |
One or more |
Simple type variables, such as int and string |
None |
Fastest |
| Print |
Language structure |
One |
Simple type variables, such as int and string |
Int |
Fast |
| Print_r |
Function |
One |
Complex types, such as arrays and objects |
Bool |
Slow |
Echo is not a function, but a php statement. it can use commas to output multiple variables without returning values, and the speed is also the fastest.
Print and echo are basically the same, but print can only output one variable and return values. if the output is successful, 1 is returned.
Print_r is a function that prints easy-to-understand information about variables. If the parameter is string, integer, or float, the variable value is printed. If the parameter is array, the key and element are displayed in a certain format. Objects are similar to arrays.
Print_r has two parameters: the first parameter is the variable, and the second parameter can be set to true. if it is set to true, the variable to be printed is returned; otherwise, the boolean value is returned.
"Xyw", "2" => "Eliot", "3" => "blog"); print_r ($ arr ); // output array $ return = print_r ($ arr); // return value: 1 echo $ return; // output 1 $ return = print_r ($ arr, true ); // returns the array echo $ return; // output array?>
Output:
Array
(
[1] => xyw
[2] => Eliot
[3] => blog
)
This article is original Eliot, reprinted please indicate the source: http://blog.csdn.net/xyw_blog/article/details/13743341