in PHP, there are two basic output methods: Echo and Print.
In this tutorial, we'll use echo and print in almost every example. Therefore, this section provides you with more knowledge about these two output statements. PHP Echo and Print statements
The difference between Echo and print:
- echo-capable of outputting more than one string
- Print-only one string is output and always returns 1
Tip: Echo is slightly faster than print because it does not return any values. PHP Echo Statement
Echo is a language structure that can be used with or without parentheses: Echo or Echo (). Display string
The following example shows how to display different strings with the echo command (also note that the string can contain HTML tags):
<? PHP Echo "; Echo "Hello world!<br>"; Echo "I ' m about to learn Php!<br>"; Echo "This", "string", "is", "made", "with multiple parameters." ;? >
Run instance display variable
The following example shows how to use the echo command to display strings and variables:
<? PHP $txt 1= "Learn PHP"; $txt 2= "W3School.com.cn"; $cars=array("Volvo", "BMW", "SAAB"); Echo $txt 1 ; Echo "<br>"; Echo $txt 2"; Echo "My car is a {$cars[0]}";? >
Running the instance PHP print statement
Print is also a language structure and can be used with or without parentheses: print or print (). Display string
The following example shows how to use the Print command to display different strings (also note that the string can contain HTML tags):
<? PHP Print "; Print "Hello world!<br>"; Print "I ' m about to learn php!" ;? >
Run instance display variable
The following example shows how to use the Print command to display strings and variables:
<? PHP $txt 1= "Learn PHP"; $txt 2= "W3School.com.cn"; $cars=array("Volvo", "BMW", "SAAB"); Print $txt 1 ; Print "<br>"; Print $txt 2"; Print "My car is a {$cars[0]}";? >
Running an instance
"PHP Learning" PHP 5 echo and Print statements