The Echo statement

  • It is also a statement used to display output in PHP.
  • It doesn't return value.
  • It allows passing multiple arguments which are separated by a comma.
  • Like that of print, echo can be used with or without parenthesis.
  • It is faster than a print statement.

Example 1: Echo statement with and without parenthesis

<?php
echo "Hello world without parenthesis"; //without parenthesis
echo "<br>"; 
echo ("Hello world with parenthesis"); //with parenthesis
?>
Output




Example 2: Displaying value of variables using echo.
<?php
$fname="John";
echo "Fname:".$fname; 
?>
Output



Example 3Displaying multiple arguments with PHP echo.
<?php
$fname="Tedy";
$lname="Kassashun";
echo "Full Name:".$fname,$lname; 
?>
Output



Example 4Return value with echo. It generates a syntax error.
<?php
$city="Adisababa:";
$coun=echo $city."Is the capital city of Ethiopia";
echo "<br>";
echo "value Returned:".$coun; 
?>
Output