In PHP the output can be seen using two statements : echo and print. Echo statement is the most basic way to display output in PHP.
Within PHP, ‘echo’ is a not a function, rather it is a language construct, so there is no need to use parentheses() with it.
PHP can be used to output both strings or variables. Following are some of the usage of echo statement in PHP.
In order to display any text, simply write the echo followed by the statement,message or text you want to display, within the quotes.
Printing text in PHP
The below example displays how you can display variables using echo statement in PHP.
In the above statement the second echo statement is used to print <br> tag. As this tag is used to provide a line break, this statement will print a line break.
The last echo statement uses combination of strings and variables. Multiple strings are connected in PHP using (.) dot operator. This is known as concatenation in PHP.
Each user defined string must be passed within quotes in PHP.
Difference between Echo and Print in PHP
In PHP, Echo and Print bot statements are used to output data but with some differences
– Echo has no return value while print has return value of 1
– Echo can have multiple parameters while print has only one parameter
– Echo statement is faster than print statement.
Tags – Echo vs Print statement, Different between echo and print statements in php. How to print a message or variable in php.