PHP echo statement Tutorial
PHP echo Statement
It is a language construct used to display one or more values in a browser.
Language constructs are constructs from which the language is made of. Language constructs are building blocks of the language.
Ex. Keywords, Data types, Constants, Operators, Separators etc.
I.e. break, if, for, while, echo, print, return, ==, etc.
Language constructs can be written in more than one ways and they may or may not return a value. As echo is a language construct, it can be written; with or without brackets and does not return any value.
Displaying text using echo:
Ex: // both are equivalent statements
echo “Hello World”; OR echo (“Hello World”); // Hello World
Displaying multiple values:
PHP echo: accepts comma separated list of values.
When used brackets, it does not accept multiple values; we must and should pass a single value.
echo "Hello World " , 1; // Hello World 1
echo ("Hello World ",1); // Syntax error: unexpected ,
Note: It is recommended to use echo without brackets.
Most of the language constructs can only be used as standalone statements,
I.e. they are not meant to be placed one inside other.
// echo(echo("Hi")); // Syntax error : unexpected ‘echo’ (T_ECHO)
Because echo must be used as a standalone statement
1. PHP stands for ______________
a. Hypertext Preprocessor
b. Preprocessor Hypertext
c. Personal Home Processor
d. Personal Hypertext processor