1、 The difference between the two
Echo supports multiple string outputs, separated by commas (,), and print only supports one string output;
Echo output speed is faster than print;
Echo has no return value, and the return value of print is always 1.
Echo is a language structure function, which can be used with () or without parentheses.
Echo ("this is a string output"); Echo "this is a string output";
The use of print is consistent with echo
Knowledge point expansion：
Generally speaking, the dynamic output of HTML content in PHP is realized through print and echo statements. In practical use, the functions of print and echo are almost the same. It can be said that where one can be used, the other can also be used. However, there is also a very important difference between the two: in the echo function, multiple strings can be output at the same time, while in the print function, only one string can be output at the same time. At the same time, the echo function does not need parentheses, so the echo function is more like a statement than a function.
When writing PHP code, I prefer to use echo () to output strings, but I also find that many people use the print () function to output strings. I still don’t understand the difference between using echo () and print ()? In my opinion, their functions are the same.
However, I also think they must be different, but I don’t know it yet.
What’s the difference between them? I decided to find out.
There is no return value after echo output. Print has a return value
By consulting relevant data, it is found that there are subtle differences between the two functions.
According to the data, there is no return value after echo output, but print has a return value. When its execution fails, it returns flash. Therefore, it can be used as a normal function. For example, after executing the following code, the value of variable $r will be 1.
$r = print “Hello World”;
This means that print can be used in some complex expressions, but echo can’t.
However, because the echo statement does not require any value to be returned, the echo statement in the code is slightly faster than the print statement.