In general, the dynamic output of HTML content in PHP is achieved through print and ECHO statements, and in practice, both 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
If you have to add parentheses, note that echo (' A ', ' B ', ' C ') is wrong and should be written as:
Echo
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
All of it can be used in more complex expressions.
Plus,Echo's efficiency is relatively fast !
Look at the following code:
<? $a= ' Hello '; $b= ' php world! '; Echo $a,$b. ' <br/> '; // print$a. $b. ' <br/> '; // ?>
Analysis Summary:
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 <<<print <<<
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
It is believed that this article has some reference value for us to master PHP program design better.
The difference between Echo and print in PHP