PHP echo & print

Last Updated: February 5, 2022

echo

echo and print are two ways to get output in PHP

echo and print are more or less the same. These commands are used to output something on your screen.

echo has no return value

 echo(string ...$expressions): void

Its arguments are a list of expressions following the echo keyword, separated by commas.

<?php
echo "<h2>PHP is easy to learn!</h2>";
echo "Hello world!<br>";
echo "Multiple parameters ", "string ", "one ", "two ", "three";
?> 

echo also has a shortcut syntax as shown below

I have <?=$foo?> foo.

print

print command has a return value 1

 print(string $expression): int

print is not a function but it is a language construct in PHP. print accepts only one parameter

Examples

<?php
print "hello";
// outputs "hello"
Test