In PHP, there are two basic output methods: Echo and Print
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
<?phpecho "
Show variables<?php$txt1= "Learn PHP"; $txt 2= "W3School.com.cn"; $cars =array ("Volvo", "BMW", "SAAB"), Echo $txt 1;echo "<br>"; echo "Study PHP at $txt 2", echo "My car is a {$cars [0]}";? >
PHP Print StatementPrint is also a language structure and can be used with or without parentheses: print or print ().
Display string<?phpprint "
Show variables<?php$txt1= "Learn PHP"; $txt 2= "W3School.com.cn"; $cars =array ("Volvo", "BMW", "SAAB");p rint $txt 1;print "<br> ";p rint" Study PHP at $txt 2 ";p rint" My car is a {$cars [0]} ";
?>
PHP Echo and Print