What is the difference between echo (), print (), Print_r (), and return in PHP?
Often there are a lot of novice and not too use print () Friends to answer this question so that the interview failed.
So what's the difference between them? Now let's take a look at
Answer:
ECHO is a PHP statement, print and Print_r are functions, statements have no return value, and functions can have return values (even if they are not used)
Print () only prints the value of a simple type variable (such as int,string)
Print_r () can print out the values of complex type variables (such as arrays, objects)
The return statement exits from the current function and returns a value from that function.
echo outputs one or more strings
echo-output one or more strings
Descrīption
void Echo (String arg1 [, String ...])//return value is NULL
echo "Hello", "friend";
print– output A string
Descrīption
int print (string arg)//return value is cosmetic
print "Hello friend";
You can do these things
$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])//Returns the value is Boolean, the parameter is a mix type, can be a string, shaping, array, object class Print_r () to display information about a variable easily understandable. If a string, integer, or float is given, the variable value itself is printed. If you give an array, the keys and elements will be displayed in a certain format. object is similar to an array.
Note: Print_r () will move the array pointer to the last edge