PHP Echo and Print Statement

Echo and Print is a statement in the PHP programming language. PHP echo statement and the print statement is used for displaying a program output of a specific block of code. Any function result, Strings, conditions, etc can be displayed on the screen by echo statement. In the previous article, we have already used this statement in examples. In this article, we will learn about PHP Echo and Print statement in details.

PHP Echo Statement

Echo is not a function in PHP scripting language. Because it can be used without parenthesis. But parentheses can be used with Echo this statement. Echo is just used for output data on the screen. You can you a different kind of things using echo. But it has a basic implementation for getting output.

You can use the echo statement to display program data by one of the three above them. Echo is not case sensitive. But the official recommendation of using Echo statement is echo. Every echo statement ends with a semi-colon (;).

Displaying Strings

The string is a plain word or sentence in programming languages. When a programmer wants to display a word or sentence on the screen, he has to write the sentence as a string and put it in the echo statement. But how can we implement the echo statement for getting an output of the string?

After defining the echo statement, you have to put the string in a quotation mark "string goes here" and you also have to remember to put the semi-colon at the end of the echo statement. So the implementation of displaying string will be echo "string goes here";.

Example:

<?php
echo "String and will be displayed for echo statement";
?>

Output:

String and will be displayed for echo statement

Displaying multiple arguments string

If you have some different string from the different location then you can use those string together to get output in a single line. Alternatively, you can break down a long sentence string or multiple arguments to the echo statement instead of using a single argument. In the same way, you have to put the string argument in the quote mark "". But for separating the multiple arguments you have to use, ","operator between two string argument.

Suppose you have two arguments one is “Program” and another is “is fun!”. Now see the example below: