PHP echo() Function

Definition

The echo() function outputs one or more strings.

The echo() function is not a function, so parentheses are not required.

Syntax

PHP echo() function has the folloiwng syntax.

echo strings;

Parameter

ParameterIs RequiredDescription
stringsRequired.One or more strings to be sent to the output

Return

No value is returned

Example 1

Write some text to the output:


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

The code above generates the following result.

Example 2

Write the value of the string variable ($str) to the output:


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

The code above generates the following result.

Example 3

Join two string variables together


<?php// w  w  w. ja v  a  2  s . c  o  m
$str1="Hello world!";
$str2=" from java2s.com!";
echo $str1 . " " . $str2;
?> 

The code above generates the following result.

Example 4

Write the value of an array to the output


<?php
$age=array("PHP"=>"5");
echo "PHP is " . $age['PHP'] . " years old.";
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions