Php Learning Log (3)-echo & print, php Learning Log-echo
In php, there are two methods to output the result: echo and print. The following compares the two methods.
Differences between echo and print:
|
Echo |
Print |
Continuous output string |
Continuous output of multiple strings |
Only one string can be output. |
Return Value |
None |
Return 1 |
Usage |
Echo or echo () |
Print or print () |
(1) echo can output multiple consecutive strings, and print can only output one string:
Instance 1:
<? Php/* echo can output multiple consecutive strings, and print can only output one string */echo "echo outputs one string:"; echo "hello, world "; // echo outputs a string echo "<br/>"; echo "echo outputs multiple strings:"; echo "hello, world", "hello, php", "hello, python "; // echo outputs multiple strings echo" <br/> "; print" print outputs a string: "; print" hello, world "; // print outputs a string print "<br/>";/* start-[print outputs multiple strings consecutively]-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. php on line 14/* end-[print multiple consecutive strings]-end */print "<br/>";?>
The code that shields print from outputting multiple strings consecutively. The result is as follows:
If you do not block the code that outputs multiple strings consecutively by print, an error occurs (syntax error ):
(2) No return value for echo. print always returns 1.
<? Php/* print returns 1, and echo does not return the value */$ print_value = print "hello, world <br/>"; // result: hello, worldprint "returns $ print_value "; // result: the returned value is 1 $ echo_value = echo "hello, world <br/>"; // syntax error?>
(3) There is no difference between the output mode with and without brackets. I will not explain it here.
Technorati labels: php, echo, print