Generally, peoples are call out PHP echo is a function, however, the echo in PHP is not a function but it is a language construct. This PHP echo statement is majorly used for displaying the value of variables and strings on the web page.
In the above paragraph, we use the term language construct, which means the control structure of a programming language. You can get more details about language construct from here https://en.wikipedia.org/wiki/Language_construct.

How to Write echo Statements in PHP
1 2 3 |
<?php echo "<h2>PHP Echo is Fun!</h2>"; ?> |
Some of the major points and the use of echo in PHP programming are,
- echo is a statement that is used for displaying the output.
- PHP echo does not return any value, which means it is a void type.
- In echo, it can print variable, string, and comma-separated strings.
- print is also used for display output but echo is faster.
- echo can be written without and with parentheses: echo, and echo().
Also Read: How PHP Code Works
Now we check some most useful examples which help to better understand echo statements in PHP.
Display Strings of Text by Using echo
1 2 3 4 5 6 7 8 |
<?php //simple strings echo "I'm learning about PHP Echo!"; //displaying comma seprated strings as a complete statement echo "These ", "are ", "comma ", "separated ", "strings."; ?> |
Output:
I’m learning about PHP Echo!
These are comma-separated strings.
Display HTML Code Using PHP echo
1 2 3 4 |
<?php // Displaying HTML code using PHP echo echo "<h3>This is a simple heading.</h3>"; ?> |
Output:
This is a simple heading.
You can also use styling with HTML within the PHP echo statement,
1 2 3 |
<?php echo "<p style='color: red;'>This is heading with style color red.</p>"; ?> |
Output:
This is heading with style color red.
Display Variables Value
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?php // Defining variables $text = "Hello World!"; $number = 123456789; $arrayData = array("BB", "CC", "John"); // Displaying variables echo $text; echo "<br>"; echo $number; echo "<br>"; echo $arrayData[0]; ?> |
Output:
Hello World!
123456789
BB
Here is a complete tutorial and reference of the PHP echo statement with some important examples which help anyone to better understand and use echo in the time of PHP programming.
If you facing any issues while using it, please let me know in the comment.
Also Read:
- Multiple Barcode Generator in PHP
- Get Current City State and Zip Code Using PHP
- How to Use Expression of Multiline String in PHP
- How to Execute PHP File From Command Line
Happy Coding..!