In the previous tutorial we learnt about PHP variables. In this tutorial we will show how to display echo and print in PHP, showing those variables on a screen.

In PHP there are two ways to output something on a screen: Echo and Print. They are so called language constructors. This is why they can be used with or without parentheses like print(),echo(). 

They are almost the same, with some slight differences. Below you can see those differences in detail.

The difference between Echo and Print in PHP

  • Since it returns a value of 1, Print is best used within expressions.
  • The function Echo does not return any value.
  • Echo is faster than print.
  • Print takes only one argument.
  • Your Echo can take multiple parameters.

Examples of use:

A simple example of echo and print:

<?php
echo "In PHP you can either use the echo statement, <br />";
print "or the print statement, to output text.<br />";
?>

The above example outputs the following in your browser:

In PHP you can either use the echo statement, or the print statement, to output text.

You can combine multiple strings by using a “.” (dot).

<?php
$str1 = "In PHP you can glue";
$str2 = $str1 . " strings together using a dot";
?>

Echo

Technical details

SyntaxEcho ($strings)
ParametersExpression – One or more string expressions, separated by commas.
Return valueNo value is returned

Print

Technical details

SyntaxPrint ($string)
ParametersExpression – The expression to output. Non-string values will be coerced to strings.
Return valueAlways returns 1.

In conclusion, we hope that this tutorial provided you with value. Do you need further information on how to’s for PHP? Feel free to check other articles at PHP. We are your source for all things PHP!