Learn PHP Echo Statement

Learn PHP Echo Statement.
PHP echo statement can be used to print the string, multi-line strings, escaping characters, variable, array, number etc.
echo is not function. it is statement.

Let see below example

<?php
echo "Hello, Learn Php easily";
?>

Output :
Hello, Learn Php easily

Echo Statement Features,

1. echo is a statement, which is used to display the output.
2. echo can be used with or without parentheses: echo(), and echo.
3. echo does not return any value.
4. We can pass multiple strings separated by a comma (,) in echo.
5. echo is faster than the print statement.

PHP echo - printing variable value and variable name.
In double quote(" "), PHP echo is printing variable value
<?php
$str="Hello learn PHP";
echo "Inside double quote is: $str";
?>
Output:
Inside double quote is: Hello learn PHP

In Single quote(' '), PHP echo is printing variable name
<?php
$str="Hello learn PHP";
echo "Inside double quote is: $str";
?>
Output:
Inside Single quote is: $str
echo statement doesn't return any value

Below example gives Parse error. it doesn't return any value

PHP Code Example :
<?php
print echo("");
?>

PHP echo - printing multi line string using NOW doc and Heredoc representation

<?php
echo <<<"EOF"
Heredoc representation<br>
Good morning!!!<br>
How are you??<br>
EOF;

echo <<<'NOW'
NOWdoc representation<br>
Good mkorning!!!<br>
How are you??<br>
NOW;
?>

Output:

Heredoc representation
Good morning!!!
How are you??
NOWdoc representation
Good mkorning!!!
How are you??

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

61434