PHP echo() Function

PHP crypt() Function
PHP explode() Function

In this article, you will learn how to output one or more strings. The echo() function outputs one or more string.

Interesting facts about PHP echo function

  • Echo function is actually not a function because it does not required parentheses to call.
  • However, if you want to use multiple parameters to the echo function, parentheses are required.
  • Echo function is slightly faster than the print() function in PHP.

What is the syntax of the ECHO() function in php?

echo(strings)
ParameterDescription
stringsString or Strings to output – Required
PHP ECHO() method

Examples of the ECHO() function

Example 1. In this example, we simply output the given string.

<?php
echo "Hello PHP!";
?>

Example 2. In this example, we store the string in variable and the echo that variable.

<?php
$str = "Hello world!";
echo $str;
?>

Example 3. In this example, we take two string and output using echo function at the same time by concatenating them.

<?php
$str_1="Hello PHP!";
$str_2="What a sunny day!";
echo $str_1 . " " . $str_2;
?> 

Example 4. In this example, we output the value of array using echo function.

<?php
$age=array("Jawad"=>"25");
echo "Jawad is of: " . $age['Jawad'];
?>

Example 5. In this example, we use the single and double quotes with the echo function. Single quotes print the name of the variable but not the value.

<?php
$color = "red";
echo "Roses are $color";
echo "<br>";
echo 'Roses are $color';
?>
PHP crypt() Function
PHP explode() Function
en English
X
Scroll to Top