Skip to content

PHP Tutorial PHP Syntax and Output

PHP print

Lesson 14 of 369 2 min read By Deepak Paswan Updated Oct 5, 2026

print does almost the same thing as echo. It prints one value.

index.php
PHP
<?php
print "Hello from print";
Output
OUTPUT
Hello from print

The differences

echoprint
Several values with commasYesNo, only one value
Returns a valueNoYes, always 1
Slightly fasterNot noticeablyNot noticeably
Used in real codeVery oftenRarely

The return value

Because print returns 1, you can use it inside an expression. This is rarely useful, but it shows the difference.

index.php
PHP
<?php
$result = print "Hi\n";
echo $result;
Output
OUTPUT
Hi
1

echo cannot do this, because it returns nothing.

Other ways to print

PHP has more output tools. You will use them later.

  • printf() and sprintf() print formatted text. See Formatting Strings.
  • print_r() and var_dump() show the contents of variables while you debug. See Type Checking.
info
Which one should you use?
Use echo. It is the common style, it accepts several values and it is what you will see in almost all PHP code and in WordPress themes.