PHP echo

Beginner
5 min read
Updated: Nov 2026
3 examples
Language construct

Definition and Usage

echo sends one or more expressions to the output. PHP does not add a space or a newline between them. echo "hello", "world"; prints helloworld.

echo is a language construct, not a function. The arguments are a comma list after the keyword. It has no return value, so it cannot sit where PHP expects an expression. Non-string values are cast to string, even when strict_types is on. echo 6 * 7; prints 42.

Not an expression.

($ok) ? echo "yes" : echo "no"; does not parse. Pass the ternary in: echo $ok ? "yes" : "no";.

PHP Syntax

A comma list, or the short echo tag inside a template. The short tag stays available when short_open_tag is Off.

PHP
echo expression, expression, ...;

<?= $expression ?>

Parameters

ParameterRequired?Description
expressionsYesOne or more expressions, separated by commas. PHP casts a non-string to string before sending it.

Return Value

ResultMeaning
No valueecho cannot be assigned or used as a condition
print returns 1print takes one expression and can appear inside a larger expression

Commas also dodge concatenation precedence. echo "Sum: ", 1 + 2; prints Sum: 3 because 1 + 2 is its own argument. With the dot, write the parentheses yourself: echo "Sum: " . (1 + 2);.

PHP Examples

Three scripts. Run them with php echo.php.

Example 1 — Comma arguments

1 + 2 is its own expression. echo does not insert a space between arguments.

PHP
<?php
echo "Sum: ", 1 + 2, "\n";
echo "hello", "world", "\n";
echo "hello world", "\n";

How It Works

  1. 1 + 2 is evaluated to 3, then sent.
  2. "hello" and "world" are written with nothing between them.
  3. The space in "hello world" is part of that string.

Example 2 — Parentheses belong to the expression

echo("hello") is not a function call. The parentheses wrap the value being output.

PHP
<?php
echo "hello", PHP_EOL;
echo("hello"), PHP_EOL;
echo(1 + 2) * 3, PHP_EOL;

How It Works

  1. echo("hello") outputs hello. The parentheses group that string.
  2. echo(1 + 2) * 3 is echo ((1 + 2) * 3), so the output is 9.
  3. echo("hello", "world"); does not parse. A comma list cannot sit inside one pair of parentheses.

Example 3 — Double quotes, single quotes, and <?=

Double quotes interpolate. Single quotes do not. The short echo tag prints one expression in a template.

PHP
<?php
$name = "Ada";
echo "Hello, $name", PHP_EOL;
echo 'Hello, $name', PHP_EOL;
?>
<p><?= $name ?></p>

How It Works

  1. "Hello, $name" replaces $name with Ada.
  2. 'Hello, $name' prints the dollar sign and the name of the variable.
  3. <?= $name ?> is short echo. It does not depend on short_open_tag.

Frequently Asked Questions

No. echo is a language construct. It has no return value, so you cannot write $out = echo "hi"; or call it through a variable function. Named arguments do not apply.
The parentheses belong to the expression, not to a function call. PHP reads echo(1 + 2) * 3 as echo ((1 + 2) * 3). echo("hello", "world"); is a parse error because ("hello", "world") is not one expression.
echo accepts a comma-separated list of expressions and returns nothing. print accepts one expression and returns 1, so print can sit inside a larger expression. echo is the usual way to send output.
No. <?= $name ?> is always available, even when short_open_tag is Off. It is the same output as <?php echo $name; ?>.

Next: PHP Strings

Single quotes, double quotes, and the . operator that echo commas can replace.

PHP Strings →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

18 people found this page helpful