Echo Statement In PHP
In this article, you will learn how to effectively use PHP echo statement in your PHP code, whether you are a beginner or an experienced developer. Learn how to use PHP echo, the versatile command that effortlessly injects dynamic content into your web pages, making them come alive with personalized messages, data, and more.
Let’s dive into the PHP echo statement and explore its world.
PHP echo Statement
In PHP programming, the echo statement is one of the most commonly used constructs for showing data on the screen.
A dynamic and interactive web page is created by using PHP echo, which is fundamental and essential to PHP programming.
It’s easy to use echo; we may consider it as PHP basics. Simply add your desired string or value inside the parentheses of the echo statement.
As an example, the following code displays the string “This is how echo works” on the screen:
echo Example: 1
echo can be used with or without parentheses: echo or echo().
Here is a simple example of how you can output text using the echo command (note that the text can be formatted in HTML markup):
With the echo statement, you can output text and variables, as shown in the following example:
Additionally, you can use PHP echo to concatenate multiple strings.
To do this, we use the period (.) operator, which joins two strings together.
Consider the following examples:
The code declares two variables, $first_name and $last_name, and assigns the strings “Elon” and “Musk” to them respectively.
The echo statement is used to output a string to the screen.
The dot operator is used to combine (or concatenate) multiple strings into one string.