The echo statement can output one or more strings. In general terms, the echo statement can display anything that can be displayed to the browser, such as strings, numbers, variables values, the results of expressions, etc.
Since echo is a language construct not actually a function (like if
a statement), you can use it without parentheses e.g. echo
or echo()
. However, if you want to pass more than one parameter to echo, the parameters must not be enclosed within parentheses.
Display Strings of Text
Display HTML Code
This is a simple heading.
This is heading with style.
Display Variables
123456789
Red
PHP print Statement
You can also use the print statement (an alternative to echo
) to display output to the browser. Like echo the print is also a language construct not a real function. So you can also use it without parentheses like: print
or print()
.
Both echo
and print
statement works exactly the same way except that the print
statement can only output one string, and always returns 1. That's why the echo
statement is considered marginally faster than the print
statement since it doesn't return any value.
Display Strings of Text
The following example will show you how to display a string of text with the print statement:
The output of the above PHP code will look something like this:
Hello World!
No comments:
Post a Comment