Two basic ways to get output in PHP are Echo and Print. Echo and Print are most likely same. Both are used to output data to the screen. But Echo is faster than Print. To print some value in PHP
You can use the following
OUTPUT OF THE ABOVE CODE WILL BE…
Same can also be achieved using the following code
OUTPUT OF THIS WOULD ALSO BE SAME AS ECHO i.e.
Now question arises …
DIFFERENCE BETWEEN ECHO AND PRINT
- In terms of speed, “echo” is speeder than “print”.
- “echo” does not return while “print” returns 1
This will be discussed later. But you can take a note of this.
ECHO | ||
What is it? | In PHP, Echo is a language construct rather than function. | Although it is also a language construct, but it behaves like a function in that it returns a value. |
Syntax | void echo(string $args1 [string $arg1,string $..]) | int print (string $arg) |
Parameters | Takes more than one parameter when used without parenthesis. The syntax is: echo expression[,expression [,expression ]…] | Takes only one parameter. |
Return type | Echo doesn’t return any value. | Print always return 1. |
Speed | Echo is faster than Print. | Print is slower than Echo. |
Leave a comment