Home >Backend Development >PHP Tutorial >What is the difference between echo(), print(), print_r()? _PHP Tutorial
echo is a PHP statement, print and print_r are functions, statements have no return value, functions can have return values (even if they are useless)
print can only print out the values of simple type variables (such as int, string)
print_r can Print out the value of complex type variables (such as arrays, objects)
echo -- Output one or more strings
Description
void echo ( string arg1 [, string ...] ) / /The return value is empty
echo "Hello", "Friend";
print --output a string
Description
int print ( string arg )//return The value is an integer
print "Hello 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 the variable.
bool print_r (mixed expression [, bool return] ) //The return value is Boolean, the parameter is mix type, which can be string, integer, array, object class print_r() displays easy-to-understand information about a variable information. If a string, integer or float is given, the variable value itself will be printed. If an array is given, the keys and elements will be displayed in a certain format. object is similar to an array.
print_r() will move the array pointer to the end.
You can
print_r(str);
print_r(int);
print_r(array);
print_r(obj);
You can also use var_dump var_export