Php echo print print_r difference analysis
Echo is a PHP statement, print and print_r are functions, and the statement does not return values. The function can return values (even if it is not used)
Print () can only print values of simple type variables (such as int and string)
Print_r () can print values of complex types of variables (such as arrays and objects)
Echo outputs one or more strings
Echo -- output one or more strings
Definition and usage
The echo () function outputs one or more strings.
Syntax
Echo (strings) parameter description
Strings is required. One or more strings to be sent to the output.
Tips and comments
Note: echo () is actually not a function, so you do not need to use parentheses for it. However, if you want to pass one or more parameters to echo (), a parsing error occurs when brackets are used.
Tip: The echo () function is a little faster than the print () function.
Tip: The echo () function can use the simplified syntax. See example 5.
Example
Example 1
<? Php
$ Str = "Who's John Adams? ";
Echo $ str;
Echo "<br/> ";
Echo $ str. "<br/> I don't know! ";
?> Output:
Who's John Adam?
Who's John Adam?
I don't know!
Descr resume ption
Void echo (string arg1 [, string...]) // the returned value is null.
Echo "Hello", "friend ";
Print -- output a string
The print () function outputs one or more strings.
Syntax
Print (strings) parameter description
Strings is required. One or more strings sent to the output.
Tips and comments
Note: The print () function is not actually a function, so you do not need to use parentheses for it.
Note: The print () function is a little slower than echo ().
Descr resume ption
Int print (string arg) // The return value is an integer.
Print "your good friend ";
You can perform the following operations:
$ Name = print "nihao n ";
$ Str = 'Test print value is $ name .';
Eval ("$ print =" $ str ";");
Echo $ print;
Print_r -- print easy-to-understand information about variables.
Bool print_r (mixed expression [, bool return]) // The return value is Boolean and the parameter type is mix. It can be a string, an integer, an array, and an object class print_r () displays easy-to-understand information about a variable. If the value is string, integer, or float, the variable value is printed. If array is provided, keys and elements are displayed in a certain format. Objects are similar to arrays.
Print_r () moves the array pointer to the last edge.
You can
Print_r (str );
Print_r (int );
Print_r (array );
Print_r (obj );
You can also use var_dump var_export.
In php, the content of the arrays output by the print_r function is not arranged. To make the output look better. For example, arrays have multiple layers. To list segments, we can write as follows:
Echo "<pre> ";
Print_r xxxxx;
Echo "<pre> ";