PHP Print

In this tutorial, you will learn how to use PHP print statements to print any message in the web browser with the help of examples.

PHP print is similar to echo statement and can be used alternative to echo statement many times. This is also a language construct not any function. Therefore you can use print statements with or without parentheses like print or print().

The main difference between PHP print and PHP echo is that PHP print can have only one argument as an input while PHP echo can have multiple.

Another difference is that PHP print always returns  1 while PHP echo does not return anything.

PHP print syntax

int print(string $arg)

Like echo statements, PHP print also used to print a string, multi-line string, escaping characters, variable value, array, etc. Below are some features of PHP print that you must know:

  • PHP print is used to print a string, variable, array, etc. This is an alternative to PHP echo.
  • This can be used with or without parentheses: print, print()
  • print can accept only one argument.
  • The return value of PHP print is always 1.
  • This is slower than PHP echo.

PHP print: printing string

print "Hello Tutorialsbook by PHP print "; 
print ("Tutorialsbook by PHP print()"); 


Hello Tutorialsbook by PHP print Tutorialsbook by PHP print()

PHP print: printing multi-line string

print "PHP print by Tutorialsbook.
This is the example of
PHP print multi-line by PHP print statement."; 


PHP print by Tutorialsbook. This is the example of PHP print multi-line by PHP print statement.

PHP print: print escaping character

echo "PHP print by \"Tutorialsbook\""; 


PHP print by “Tutorialsbook”

PHP print: printing variable value

//defining the variables 
$text = "Welcome to the World of PHP!"; 

$num1 = 15; 

$num2 = 20; 

//echoing the variables 
print $text."\n"; 

print $num1."+".$num2."="; 

print $num1 + $num2; 


Welcome to the World of PHP!

Please get connected & share!