PHP 5 echo and print statements
In PHP, there are two basic ways to output: echo and print.
In this chapter, we will discuss the usage of the two statements in detail and demonstrate how to use echo and print in examples.
PHP echo and print statements
The difference between echo and print:
- echo - can output one or more strings
- print - only allows outputting one string, and the return value is always 1
Tip:echo outputs faster than print. echo has no return value, while print has a return value of 1.
PHP echo statement
echo is a language construct. When using it, you can either omit the parentheses or add them: echo or echo().
Display strings
The following example demonstrates how to use the echo command to output strings (strings can contain HTML tags):
Example
Try it Yourself »
Display variables
The following example demonstrates how to use the echo command to output variables and strings:
Example
Try it Yourself »
PHP print statement
print is also a language construct. You can use parentheses or not: print or print().
Display strings
The following example demonstrates how to use the print command to output strings (strings can contain HTML tags):
Example
Try it Yourself »
Display variables
The following example demonstrates how to use the print command to output variables and strings:
Example
Try it Yourself »