What is the usage of echo in PHP?

In PHP, the echo statement is used to output strings or variables. Its usage is:

echo "Hello World!";

This will produce the string “Hello World!”.

In addition to echoing strings, echo can also output the values of variables:

$name = "John";
echo $name;

This will output the value of the variable $name, which is “John”.

In addition, echo can also output multiple strings or variables, which will be displayed continuously.

$age = 25;
echo "My name is " . $name . " and I am " . $age . " years old.";

This will display “My name is John and I am 25 years old.”

It is important to note that echo is a statement, not a function, so the parentheses can be omitted when using it. However, when outputting multiple variables, they need to be concatenated using the “.” operator.

bannerAds