In PHP, there are two ways to output a result: Echo and print, which will be compared in two ways.
The difference between Echo and print:
|
Echo |
Print |
| Continuous output string |
Ability to output multiple strings consecutively |
Only one string can be output |
| return value |
No |
Returns 1 |
| Usage |
echo or Echo () |
Print or print () |
(1) Echo can output multiple strings consecutively, print can only output one string:
Example 1:
<?PHP/*echo can output multiple strings consecutively, print can only output one string*/Echo"Echo Outputs a string:";Echo"Hello,world";//echo outputs a stringEcho"<br/>";Echo"Echo Outputs Multiple strings:";Echo"Hello,world", "hello,php", "Hello,python";//echo Output multiple stringsEcho"<br/>";Print"Print output a string:";Print"Hello,world";//print output A stringPrint"<br/>";/*start-"Print continuous output of multiple strings"-start*/
Print "Print output multiple strings:"; Print "Hello,world", "hello,php", "Hello,python"; // print output multiple strings, error prompt: Parse error:syntax error, unexpected ', ' in c:\users\13842\phpstormprojects\test\print& echo.phpon line +/*end-"Print continuous output multiple strings"-end*/print "<br/>" ;? >
Block "Print continuous output multiple strings" code, the result is as follows:
If you do not block the code "Print continuous output multiple strings", an error (syntax error) occurs:
(2) Echo no return value, print always returns 1
<? PHP /* Print returns 1,echo no return value */ $print _value=print "hello,world<br/>"; // results: Hello,world Print "Return value is $print _value"; // Result: The return value is 1 $echo _value=echo "hello,world<br/>"; // A syntax error has occurred ?>
(3) The output mode, with brackets and without brackets is no different, there is no explanation.
Technorati Tags: php,echo,print
PHP Learning log (3)-echo&print