3 examples of PHP Print statement

The print statement of PHP

The Print statement or command in PHP is used to display the output of a given variable or expression.

See an example of print statement

The PHP print statement can display the output of any type of data.

The print Syntax

Following is the syntax of the print statement:

print <expression>;

An example of print statement

In this example, a string and a variable are displayed by using the print statement.



Example 2:



Single line print statement



Multi-line PHP print statement

Following is an example of the multi-line single print statement:

PHP print statement

Experience this example online



Be careful when printing quotes!

Follow these guidelines to use quotes as using the print statement to display strings.

  • Use a backslash () within the strings to escape your quotes. Before the quotation mark just place a backslash.
  • Inside your strings, use single quotes (‘ ‘)

See examples below:



Printing a variable is simple in PHP. It simply requires writing the print statement which is followed by a variable name. See examples below:

Experience this example online



Output is : Hello Mike. My name is: 4a

Experience this example online



Output is : 30

Useful Reading: PHP printf function | PHP print_r function


Was this article helpful?

Related Articles

Leave A Comment?