Brief analysis of the differences between echo of print of print_r of return

  • 2020-11-20 06:03:02
  • OfStack

What is the difference between echo(),print(),print_r(),return?

There are a lot of newbies and people who don't use print() who fail to answer this question.

So what's the difference? So let's see

The answer:
echo is an PHP statement, print and print_r are functions, statements do not return values, functions can return values (even if not used)
print () can only print the value of a variable of simple type (e.g. int,string)
print_r () can print out the values of variables of complex types (such as groups, objects)
The return statement exits from the current function and returns a value from that function.

echo prints one or more strings
echo - Outputs one or more strings
Descr and ption
void echo ( string arg1 [, string ...] ) // The return value is null
echo "Hello", "friend";

print wM_output 1 string
Descr and ption
int print (string arg)// The return value is plastic
print "Hello Friend";

You can do the following
$name = print nihao/n;
$str = 'test print value is ';
eval (" / $print = "$str/";" );
echo $print;

print_r - Prints easy-to-understand information about variables.
bool print_r (mixed expression [, bool return]) // The return value is Boolean, the argument is of type mix, can be string, plastic, array, object class print_r() displays easy-to-understand information about a variable. If string, integer, or float are given, the variable value itself is printed. If array is given, the keys and elements are displayed in a format of 1. object is similar to arrays.

Note: print_r() moves the pointer to the last edge of the array


Related articles: