in practical use, both the print and ECHO functions are almost identical.
It can be said that there is a place to use, and the other can be used. However, there is also a very important difference between the two:
In the Echo function, you can output multiple strings at the same time, and in the print function you can only output one string at a time. At the same time, the Echo function does not require parentheses, so the echo function is more like a statement than a function.
Echo and print are not functions, but language constructs, so parentheses are not required. The difference between them is:
(1) Echo can output multiple strings, like this:
Echo ' A ', ' B ', ' C ';
If you have to add parentheses, note that echo (' A ', ' B ', ' C ') is wrong and should be written as:
Echo (' A '), (' B '), (' C ');
It does not behave like a function, so it cannot be used in the context of a function
(2) Print can only output a string, it may behave like a function, for example, you can use the following:
$ret = print ' Hello world ';
All of it can be used in more complex expressions.
In addition, ECHO's efficiency is relatively fast ~
The following code:
<?php
$a = ' Hello '; $b = ' php world! '; echo $a, $b. ' <br/> ';//echo you can use a comma-delimited string variable to display the print $a. $b. ' <br/> ';//While print cannot use commas, it can be separated by dots, print $a, $b. ' < br/> ';//Use the comma-times error.
?>
The echo command is the same as the Print command, no difference
The Echo function differs from the print function.
Echo () No return value, same as echo command
Print () has a return value, success, return to 1,false, return 0.
printf () is similar to sprintf (), which is formatted output, but is output to standard output, which is output to a variable
Shaped like
Echo <<< EOT
EOT;
Print <<< EOT
EOT;
Written format, which has the following meanings:
The <<< operator, which treats the variables between the custom delimiters as strings,
EOT custom delimiter, must be at the beginning of the line at the end
(turn) The difference between Echo and print