PHP print | Print a Single String as Output

PHP print is not exactly a function, but a language construct which prints a single string in the output. Since it is a language construct and not a function, it is not mandatory to use parentheses with its argument list. In this article, we will discuss the PHP print Function. Also, we will discuss a few examples of using it.

Note: The major difference between print and echo is that print only accepts a single parameter. Also, print always returns 1.


print (string $argument);

print $argument;


The PHP print accepts only one parameter. The string or variable you need to print is the input the function. Also, you can concatenate multiple strings and variables in the parameter.

Return Value

The PHP print always returns 1.

PHP print


Let’s discuss a few examples of printing variables and strings.

Example 1: Print Simple String

For instance, consider a simple example of printing a string.

	print ("This is a simple statement");


In the above example, the function will simply print the input string.

This is a simple statement

Example 2: Not Using Parentheses

Similarly, you can avoid using the parentheses for the parameter list.

	print "It works without a parentheses too!";

It works without a parentheses too!

Example 3: Printing Variables

Also, you can print the value of variables.

	$stringVariable = "This is a string variable";

	$integerVariable = 10;

	print $stringVariable;

	print $integerVariable;

You can print variables by providing the variable as a parameter.

This is a string variable10

Example 4: Printing Array Elements

Similarly, you can print individual array elements. However, you cannot print the whole array using PHP print.

	$array = array('a' => 'apple');

	print $array['a'];

Also, you can use the PHP print_r Function to print arrays in PHP.

Example 5: Single Quotes Vs Double Quotes

However, there is a difference between using single and double quotes.

	$fruit = 'apple';

	print 'My favorite fruit is $fruit';
	print "My favorite fruit is $fruit"; 

The single quote prints the variable name. However, the double quote prints the value of string.

My favorite fruit is $fruit 
My favorite fruit is apple

Example 6: Concatenate Multiple Variables/Strings

Similarly, you can concatenate multiple strings and variables while using print. This can be easily done using the dot (.) operator.

	$fruit = 'Apple';

	$anotherFruit = 'Mango';

	print 'My favourite fruits are '.$fruit.' and '.$anotherFruit;
My favourite fruits are Apple and Mango


In conclusion, we discussed PHP print in this article. You can read more about it on the Official PHP Documentation. Additionally, you can learn about more PHP String Functions on Concatly.

Spread the Knowledge

Leave a Reply

Your email address will not be published. Required fields are marked *