Home » PHP » PHP Echo / Print
This tutorial helps you learn how to use a PHP Echo/Print. So, let's begin.
Both PHP echo and print are PHP statements. Therefore, you can use them to display the output in PHP.
Example:
<?php
$name="Alex";
echo $name;
//or
echo ($name);
?>
output:
Alex Alex
Create and initialize a variable($name) holding a string value=" Alex" in the example above. We want to print the name for this ($name) variable declare inside the echo with or without parentheses. It will display the same output.
<?php
$name = "Alex";
$profile = "Tutorial With Example";
$age = 26;
echo $name , $profile , $age, " years old";
?>
Output:
Alex Tutorial With Example 26 years old
<?php
$name="Alex";
print $name;
//or
print ($name);
?>
In the example above Declare a variable ($name) value="Alex". Next, we want to print the name. For this, we will simply define the $name inside the print statement with or without parentheses. It will display the output: "Alex".
Print does not output more than one.
Example
<?php
$name = "Alex";
$profile = "PHP Developer";
$age = 25;
print $name , $profile , $age, " years old";
?>
Output:
Parse error: syntax error