PHP Print

Like PHP echo, PHP print is a language construct, so we don't need to use parenthesis with the argument list. Print statement can be used with or without parentheses: print and print() and it always returns 1.

Syntax of PHP Print

int print(string $arg)

PHP Print statement generally used to print the string, multi-line strings, escaping characters, variable, array, etc and some important points that you must know about the echo statement are:

  • print is a statement, generally used as an alternative to echo at many times to show the output.
  • print used with or without parentheses.
  • print always returns an integer value, which is equal to 1.
  • Using print, we cannot pass multiple arguments.
  • print is slower than the echo statement.

Printing string using PHP Print

<?php  
print "Hello World using PHP print ";  
print ("Hello PHP Coding using print()");  
?>  

Output :

Hello World using PHP print Hello PHP Coding using print()

Multi line string output using PHP Print

<?php  
print "Hello World using PHP print  
this is multi line  
text data printed by   
PHP print statement  
";  
?> 

Output :

Hello World using PHP print this is multi line text data printed by PHP print statement

Escaping characters using PHP Print

<?php  
print "Hello escape \"sequence\" characters by PHP print";  
?>

Output :

Hello escape "sequence" characters by PHP print

Printing variable value using PHP Print

<?php  
$msg="Hello print() in PHP";  
print "Message is: $msg";    
?>  

Output :

Message is: Hello print() in PHP