In PHP echo and print both are the PHP Statement. Echo and Print are used to display the output in PHP.
- It is a statement i.e which used to display the output. Ii can be used with parentheses echo or without parentheses echo.
- It can pass multiple string separated as ( , )
- IT doesn’t return any value
- echo is faster than print
$name= “Chetan ”;
echo $name , $work , $age, “ Years Old”;
Chetan Software Developer26 Years Old
In the above example, $name , $work and $age are three variable with value=(“Chetan” , “Software Developer” and 26) respectively.
Now we want to print all three variable values together. All variables names are define inside the echo statement separated by comma or dot (, or.)
And we will get the above output.
- Print is also a statement and used to display the output. Print can be used with parentheses print ( ) or without parentheses print.
- Using print can doesn’t pass multiple argument
- print always return 1
- it is slower than echo
In the above example, Declare a variable ($name) value=”Chetan”. Now we want to print the name. we simply define $name inside print statement with or without parentheses.
it will show the output: “Chetan”
Speed of both in PHP
The speed of both statements in PHP is nearly the same. Using one over the other is not likely to yield any performance improvement in your application. Theoretically, echo is more efficient because it does not return any value.
Function vs Language Construct
Unlike most PHP string functions, both aren’t functions but language constructs. Therefore it is not required to use parentheses when using both.