The echo() function outputs one or more strings.
The echo() function is not a function, so parentheses are not required.
PHP echo() function has the folloiwng syntax.
echo strings;
Parameter | Is Required | Description |
---|---|---|
strings | Required. | One or more strings to be sent to the output |
No value is returned
Write some text to the output:
<?php
echo "Hello world!";
?>
The code above generates the following result.
Write the value of the string variable ($str) to the output:
<?php
$str = "Hello world!";
echo $str;
?>
The code above generates the following result.
Join two string variables together
<?php
$str1="Hello world!";
$str2=" from java2s.com!";
echo $str1 . " " . $str2;
?>
The code above generates the following result.
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.