PHP print Function Tutorial

The print is the one of the most popular function used in PHP scripts and programs. The print simply used to print specified data, value, variable etc. into the standard output. In this tutorial we will examine different usecases and examples about the PHP print.

print Syntax

The PHP print function has very simple syntax. It accepts single parameter which printed to the standard output.

print DATA
  • DATA is a data which can be a string, integer, variable etc.

The print function returns an integer as the value which describes whether provided data is printed properly.

Print String

One of the most popular use cases for the print function is the printing string to the standard output. The standard output is generally a console or a web page. The string value can be provided with double quotes or using a single quoto.

print "I am";

print "I"." am "."";

print 'I am';

Print Variable

The print function can be also used to print variables or variables values easily. The variable name is provided as parameter to the print function.

$a="I am";

$b="I"." am "."";

$c='I am';

print $a;

print $b.$c;

Print Array

The array structure stores multiple items in a single variable. The array can not be printed by using the print function. The print_r fnuction can be used to print an array.


print_r $names;

print vs echo

The echo statement is another popoular way to print something in PHP. The print and echo are very same with a little differencies. The echo may accepts multiple items to print but the print accepts only single item.

Leave a Comment