PHP echo and print statements
There are two basic output methods in PHP:echoandprint.
PHP echo and print statements
The difference between echo and print:
· echo - can output one or more strings
· print - only allows one string to be output, and the return value is always 1
Tip: echo output is faster than print. echo has no return value, and print has a return value of 1.
PHP echo statement
echo is a language structure that uses You don't need to add parentheses, or you can add parentheses: echo or echo().
Display string
Example
The following example demonstrates how to use the echo command to output a string (the string can contain HTML tags)
PHP online"; echo "Hello world!
"; echo "I'm about to learn PHP!
"; echo "This", " string", " was", " made", " with multiple parameters."; ?>
Display variables
Example
The following example demonstrates how to use echo Command output variables and strings:
"; echo "Study PHP at $txt2"; echo "
"; echo "My car is a {$cars[0]}"; ?>
PHP print statement
Print is also a language structure that can use parentheses or not: print or print().
Display string
Example
The following example demonstrates how to use the print command to output a string (the string can contain HTML tags):
PHP is fun!"; print "Hello world!
"; print "I'm about to learn PHP!"; ?>
Display variables
Example
The following example demonstrates Learn how to use the Print command to output variables and strings:
"; print "Study PHP at $txt2"; print "
"; print "My car is a {$cars[0]}"; ?>