PHP echo is used to display the output of any string or variable. PHP echo can show many types of data, such as string, HTML element, numbers, and variables.
We have some great examples of echo to explain you more thoroughly, after seeing which you will know what is echo in PHP and how to use it.
Example 1 <?php echo "Hello my friends how are you"; echo "I am 25 years old"; ?> Example 2 <?php echo "Hello my friends how are you"; echo " :- "; echo "I am fine"; ?>
PHP Echo Variable
In the example shown below, you will see how variables are displayed using the echo statement.
Example 1 <?php $variable = "Hello my friends how are you"; echo $variable; ?> Example 2 <?php $variable = "Hello my friends how are you"; $variable2 = "I am fine"; echo $variable. " :- " .$variable2; ?> Example 3 <?php $text = "My name is john"; $number = "9853245789"; echo $text. " and my number is " .$number; ?>
Display HTML Tags
If you want to use HTML tags inside your PHP code, you can do something like this.
Example 1 <?php echo "<h1>My name is john</h1>"; echo "<h2>I am 35 years old</h2>"; echo "<h3>I have BMW</h3>"; echo "<p>This is just my dummy information</p>"; ?> Example 2 <?php $var1 = "My name is john"; $var2 = "I am 35 years old"; echo "<h1>$var1</h1>"; echo "<h2>$var2</h2>"; ?> Example 3 <?php $age = "25"; $vehicle = "BMW"; echo "My age is $age"; echo "<br>"; echo "and i have a $vehicle"; ?> Example 4 <?php $link = "google.com"; ?> <a href="<?php echo $link; ?>">click here</a>
The example below displays how you can display the PHP Array output.
Example 1 <?php $fruits = array("Apple", "Mengo", "Banana"); echo "I Need " . $fruits . ", " . $fruits ." and ". $fruits; ?> Example 2 <?php $fruits = array("Apple", "Mengo", "Banana"); echo "<pre>"; print_r($fruits); ?>
PHP Print vs Echo
PHP Print is used to display the output of an array. In the following example, you will know how to use PHP Print.
<?php $var = "My name is John"; $var2 = "I have a BMW car"; print $var; print "<br>"; print $var2; ?>
Frequently Asked Questions
We have answers to some questions that people search on the Internet every day. Let’s know what those questions are and what their answers are.
Is Echo a function in PHP?
No Echo is not a function, it is used only to show a variable and string.
What is Isset in PHP?
The isset() function which verifies a variable is set or not.
What is the difference between Print_r and echo in PHP?
The echo is used to print the output or variable and string, and Print_r mostly used to print the array value.
What is the PHP variable?
The variable inside PHP acts as a memory, inside which the input is stored.
What is $_ GET in PHP?
A variable “$ _GET” is a method that is used to get the data from forms.
What is the $_ request in PHP?
The “$_REQUEST” is a variable that is used to get the information after submitting the form.
Why Print_r is used in PHP?
This function is used to display the data stored in a variable.
How to create an array in PHP?
Using the array() function you can create an array in PHP
Note: All the examples you have seen inside this article have all been made by us and tested thoroughly. So you can use all these without any difficulty.
Read Also: 25 important examples of SQL where clause