You can display the output of PHP code by using the following two statements.

  1. Echo
  2. Print
The Print statement
  • It is a statement used to display output in PHP.
  • It returns a value of 1.
  • It doesn't allow to pass multiple arguments.
  • It can be used with or without parenthesis.
  • It is slower than an echo statement.

Example 1: Print statement with and without parenthesis


<?php
print "Hello world "; //without parenthesis 
print ("Hello world"); //with parenthesis
?>
Output



Example 2: Displaying variable value with PHP Print
<?php
$ms="Hello everyone!";
print "value is:$ms"; 
?>
Output



Example 3: Displaying multiple arguments with PHP Print. It displays syntax errors.
<?php
$ms="value 1";
$msg="value 2";
print "value is:".$ms,$msg; 
?>
Output




Example 4: Return value with PHP Print. It returns1.
<?php
$city="Adisababa:";
$coun=print $city."Is the capital city of Ethiopia";
print "<br>";
print "value Returned:".$coun; 
?>
Output