The two basic output methods of php are "echo" and "print". echo is used to output one or more strings, which can take multiple arguments and have no return value, with the syntax "echo($ str)"; and print is used to output a string that can only take one argument and has a return value, syntax "print($str)".
In PHP, there are two basic output methods: echo and print.
The difference between echo and print
- echo - output one or more strings, can accept multiple parameters and has no return value
- print - can only output a string, can only take one argument and has a return value, and always returns 1
Tip: echo is slightly faster than print because it does not return any values.
PHP echo statement
1.echo is a language construct that can be used with or without parentheses: echo or echo();
2.Display String,The following example shows how to use the echo command to display different strings (and please note that the strings can contain HTML tags)
1 2 3 4 5 6 7 8 9 10 |
|
Effect:
1 2 3 4 5 6 |
|
3.Show Variables,The following example shows how to use the echo command to display strings and variables;
1 2 3 4 5 6 7 8 9 10 |
|
效果:
1 2 3 |
|
PHP print statement
1.print is also a language construct that can be used with or without parentheses: print or print().
2.To display strings, the following example shows how to use the print command to display different strings (and note that the strings can contain HTML tags).
1 2 3 4 5 |
|
Effect:
1 2 3 |
|
3.Displaying variables, the following example shows how to display strings and variables with the print command:
1 2 3 4 5 6 7 8 9 10 |
|
Effect:
1 2 3 |
|