PHP Echo / Print

PHP Echo and Print Statements

In PHP, there are two basic ways to get output: echo and print.

They are nearly identical, and they are both used to output data to the screen.

Differences Between echo and print


The PHP echo Statement

The echo statement can be used with or without parentheses: echo or echo().

Echo Example

<?php
$txt1 = "Learn PHP";
$txt2 = "IntricateDevo";

echo "<h2>" . $txt1 . "</h2>"; echo "Study programming at " . $txt2 . "<br>"; ?>

(Note: The dot . operator is used to join or concatenate strings together in PHP).

The PHP print Statement

Just like echo, the print statement can be used with or without parentheses: print or print().

You will mostly see echo used in modern PHP applications because it is slightly faster and requires fewer keystrokes.