You are currently viewing PHP Printing Statement | Echo () Statement
  • Post category:PHP

PHP Printing Statement | Echo () Statement

Print Statement in PHP

In this article, we will see about the print statements in PHP. You can print in PHP using an echo statement.

What is PHP echo statement?

It is a language construct used to display one or more values in a browser.

Language constructs

Language constructs are constructs from which the language is made of. it is building blocks of the language.

Ex: keywords, data types, constants, operators, separators, etc.
I.e. break, if, for, while, echo, print, return, ==, etc.

Note: Language constructs can be written in more than one way 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.

Display text using echo

ex: // both are equivalent statement
echo "Hello World";
echo("Hello World");
Hello World
Hello World

How to display multiple values

The PHP echo statement accepts a comma-separate list of values. When used brackets, it does not accept multiple values, so we must and should pass a single value. It is recommended to use echo without brackets.

Example code

echo "Hello World", 1; // Hello World 1
echo("Hello World", 1); // syntax error : unexpected ,


Most of the language constructs can only be used as standalone statements, I.e they are not meant to be placed one inside the other.


echo(echo("Hi")); //syntax error : unexpected ' echo' (T_ECHO)
Because echo must be used as a standalone statement

Leave a Reply