In this article, we will see what is echo & print statements in PHP, along with understanding their basic implementation through the examples. The echo is used to display the output of parameters that are passed to it. It displays the outputs of one or more strings separated by commas. The print accepts one argument at a time & cannot be used as a variable function in PHP. The print outputs only the strings.
Note: Both are language constructs in PHP programs that are more or less the same as both are used to output data on the browser screen. The print statement is an alternative to echo.
PHP echo statement: It is a language construct and never behaves like a function, hence no parenthesis is required. But the developer can use parenthesis if they want. The end of the echo statement is identified by the semi-colon (‘;’). It output one or more strings. We can use ‘echo‘ to output strings, numbers, variables, values, and results of expressions. Below is some usage of echo statements in PHP:
Displaying Strings: We can simply use the keyword echo followed by the string to be displayed within quotes. The below example shows how to display strings with PHP.
0 Comments